java.lang.Object
de.iip_ecosphere.platform.support.yaml.Yaml

public abstract class Yaml extends Object
Generic access to YAML. Requires an implementing plugin of type Yaml or an active YamlProviderDescriptor.
Author:
Holger Eichelberger, SSE
  • Field Details

    • instance

      private static Yaml instance
  • Constructor Details

    • Yaml

      public Yaml()
  • Method Details

    • getInstance

      public static Yaml getInstance()
      Returns the YAML instance.
      Returns:
      the instance
    • setInstance

      public static void setInstance(Yaml yaml)
      Manually sets the instance. Shall not be needed, but may be required in some tests.
      Parameters:
      yaml - the YAML instance
    • load

      public abstract Object load(InputStream in) throws IOException
      Loads a plain object from an input stream.
      Parameters:
      in - the input stream to load from
      Returns:
      the mapping
      Throws:
      IOException - if accessing the input stream fails, if reading the structure fails
    • loadMapping

      public abstract Map<String,Object> loadMapping(InputStream in) throws IOException
      Loads a plain name-object mapping from an input stream.
      Parameters:
      in - the input stream to load from
      Returns:
      the mapping
      Throws:
      IOException - if accessing the input stream fails, if reading the structure fails
    • loadAs

      public abstract <T> T loadAs(String in, Class<T> cls) throws IOException
      Loads an object from YAML given as string expecting all properties.
      Type Parameters:
      T - the result type
      Parameters:
      in - the YAML string
      cls - the class/type of the object to read
      Returns:
      the object
      Throws:
      IOException - if reading the structure/object fails
    • loadAs

      public abstract <T> T loadAs(InputStream in, Class<T> cls) throws IOException
      Loads an object from YAML given as an input stream expecting all properties.
      Type Parameters:
      T - the result type
      Parameters:
      in - the input stream
      cls - the class/type of the object to read
      Returns:
      the object
      Throws:
      IOException - if reading the structure/object fails
    • loadTolerantAs

      public abstract <T> T loadTolerantAs(InputStream in, Class<T> cls) throws IOException
      Loads an object from YAML given as an input stream ignoring missing properties.
      Type Parameters:
      T - the result type
      Parameters:
      in - the input stream
      cls - the class/type of the object to read
      Returns:
      the object
      Throws:
      IOException - if reading the structure/object fails
    • loadAll

      public Iterator<Object> loadAll(InputStream in, Class<?> cls) throws IOException
      Loads all documents from a YAML file, trying to apply cls as type.
      Parameters:
      in - the input stream to load from
      cls - the class/type of the object to read; if given, only objects of that type will be returned
      Returns:
      an iterator over all documents
      Throws:
      IOException - if accessing the input stream fails, if reading the structure fails
    • loadAll

      public abstract Iterator<Object> loadAll(InputStream in, String path, Class<?> cls) throws IOException
      Loads all documents from a YAML file, trying to apply cls as type.
      Parameters:
      in - the input stream to load from
      path - the path within YAML to load from, may be null or empty for none
      cls - the class/type of the object to read; if given, only objects of that type will be returned
      Returns:
      an iterator over all documents
      Throws:
      IOException - if accessing the input stream fails, if reading the structure fails
    • loadAll

      public abstract Iterator<Object> loadAll(InputStream in) throws IOException
      Loads all documents from a YAML file.
      Returns:
      an iterator over all documents
      Throws:
      IOException - if accessing the input stream fails, if reading the structure fails
    • dump

      public abstract void dump(Object object, Class<?> cls, Writer out) throws IOException
      Dumps object in terms of cls to output.
      Parameters:
      object - the data
      cls - the class to be used as schema for writing
      out - the output writer
      Throws:
      IOException - if writing fails
    • dump

      public abstract String dump(Object object) throws IOException
      Dumps object to a string.
      Parameters:
      object - the data
      Returns:
      the YAML representation of the data
      Throws:
      IOException - if writing fails
    • dump

      public void dump(Object object, Writer out) throws IOException
      Dumps object in terms of its class to output.
      Parameters:
      object - the data
      out - the output writer
      Throws:
      IOException - if writing fails