Class Yaml
java.lang.Object
de.iip_ecosphere.platform.support.yaml.Yaml
Generic access to YAML. Requires an implementing plugin of type
Yaml or an active
YamlProviderDescriptor.- Author:
- Holger Eichelberger, SSE
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract StringDumpsobjectto a string.voidDumpsobjectin terms of its class to output.abstract voidDumpsobjectin terms ofclsto output.static YamlReturns the YAML instance.abstract Objectload(InputStream in) Loads a plain object from an input stream.loadAll(InputStream in) Loads all documents from a YAML file.loadAll(InputStream in, Class<?> cls) Loads all documents from a YAML file, trying to applyclsas type.loadAll(InputStream in, String path, Class<?> cls) Loads all documents from a YAML file, trying to applyclsas type.abstract <T> TloadAs(InputStream in, Class<T> cls) Loads an object from YAML given as an input stream expecting all properties.abstract <T> TLoads an object from YAML given as string expecting all properties.Loads a plain name-object mapping from an input stream.abstract <T> TloadTolerantAs(InputStream in, Class<T> cls) Loads an object from YAML given as an input stream ignoring missing properties.static voidsetInstance(Yaml yaml) Manually sets the instance.
-
Field Details
-
instance
-
-
Constructor Details
-
Yaml
public Yaml()
-
-
Method Details
-
getInstance
Returns the YAML instance.- Returns:
- the instance
-
setInstance
Manually sets the instance. Shall not be needed, but may be required in some tests.- Parameters:
yaml- the YAML instance
-
load
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
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
Loads an object from YAML given as string expecting all properties.- Type Parameters:
T- the result type- Parameters:
in- the YAML stringcls- the class/type of the object to read- Returns:
- the object
- Throws:
IOException- if reading the structure/object fails
-
loadAs
Loads an object from YAML given as an input stream expecting all properties.- Type Parameters:
T- the result type- Parameters:
in- the input streamcls- the class/type of the object to read- Returns:
- the object
- Throws:
IOException- if reading the structure/object fails
-
loadTolerantAs
Loads an object from YAML given as an input stream ignoring missing properties.- Type Parameters:
T- the result type- Parameters:
in- the input streamcls- the class/type of the object to read- Returns:
- the object
- Throws:
IOException- if reading the structure/object fails
-
loadAll
Loads all documents from a YAML file, trying to applyclsas type.- Parameters:
in- the input stream to load fromcls- 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 applyclsas type.- Parameters:
in- the input stream to load frompath- the path within YAML to load from, may be null or empty for nonecls- 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
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
Dumpsobjectin terms ofclsto output.- Parameters:
object- the datacls- the class to be used as schema for writingout- the output writer- Throws:
IOException- if writing fails
-
dump
Dumpsobjectto a string.- Parameters:
object- the data- Returns:
- the YAML representation of the data
- Throws:
IOException- if writing fails
-
dump
Dumpsobjectin terms of its class to output.- Parameters:
object- the dataout- the output writer- Throws:
IOException- if writing fails
-