title: Include YAML files from snakeyaml
body: <p>I would like to have YAML files with an include, similar to this question, but with Snakeyaml:
  <a href="https://stackoverflow.com/questions/528281/how-can-i-include-an-yaml-file-inside-another">How can I include an YAML file inside another?</a></p>
  
  <p>For example:</p>
  
  <pre><code>%YAML 1.2
  ---
  !include "load.yml"
  
  !include "load2.yml"
  </code></pre>
  
  <p>I am having a lot of trouble with it.  I have the Constructor defined, and I can make it import one document, but not two.  The error I get is:</p>
  
  <pre><code>Exception in thread "main" expected '&lt;document start&gt;', but found Tag
   in 'reader', line 5, column 1:
      !include "load2.yml"
      ^
  </code></pre>
  
  <p>With one include, Snakeyaml is happy that it finds an EOF and processes the import.  With two, it's not happy (above).</p>
  
  <p>My java source is:</p>
  
  <pre><code>package yaml;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.InputStream;
  
  import org.yaml.snakeyaml.Yaml;
  import org.yaml.snakeyaml.constructor.AbstractConstruct;
  import org.yaml.snakeyaml.constructor.Constructor;
  import org.yaml.snakeyaml.nodes.Node;
  import org.yaml.snakeyaml.nodes.ScalarNode;
  import org.yaml.snakeyaml.nodes.Tag;
  
  public class Main {
      final static Constructor constructor = new MyConstructor();
  
      private static class ImportConstruct extends AbstractConstruct {
          @Override
          public Object construct(Node node) {
              if (!(node instanceof ScalarNode)) {
                  throw new IllegalArgumentException("Non-scalar !import: " + node.toString());
              }
  
              final ScalarNode scalarNode = (ScalarNode)node;
              final String value = scalarNode.getValue();
  
              File file = new File("src/imports/" + value);
              if (!file.exists()) {
                  return null;
              }
  
              try {
                  final InputStream input = new FileInputStream(new File("src/imports/" + value));
                  final Yaml yaml = new Yaml(constructor);
                  return yaml.loadAll(input);
              } catch (FileNotFoundException ex) {
                  ex.printStackTrace();
              }
              return null;
          }
      }
  
      private static class MyConstructor extends Constructor {
          public MyConstructor() {
              yamlConstructors.put(new Tag("!include"), new ImportConstruct());
          }
      }
  
      public static void main(String[] args) {
          try {
              final InputStream input = new FileInputStream(new File("src/imports/example.yml"));
              final Yaml yaml = new Yaml(constructor);
              Object object = yaml.load(input);
              System.out.println("Loaded");
  
          } catch (FileNotFoundException ex) {
              ex.printStackTrace();
          }
          finally {
          }
      }
  }
  </code></pre>
  
  <p>Question is, has anybody done a similar thing with Snakeyaml?  Any thoughts as to what I might be doing wrong?</p>