Class YamlMethods
- java.lang.Object
-
- io.toro.martini.YamlMethods
-
public final class YamlMethods extends Object
Contains one-liners for reading and writing to YAML.
-
-
Constructor Summary
Constructors Constructor Description YamlMethods()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringasYaml(GloopObject gloopObject, boolean includeRoot, boolean includeNulls)Marshals a Gloop object to a YAML string.static GloopCursorgetInputCursorFromFile(String filename, List<String> yamlNodeNames, GloopExecutionContext context)Return a Gloop input cursor for reading the entries of a large YAML file.static GloopCursorgetInputCursorFromInputStream(InputStream inputStream, List<String> yamlNodeNames, GloopExecutionContext context)Return a Gloop input cursor for reading the entries of a large YAML stream.static StringgloopModelToYamlString(GloopObject gloopObject)Marshals a Gloop object to a YAML string.static GloopObjectinputStreamToGloopObject(InputStream yamlStream)Unmarshal a YAML stream to a Gloop object.static GloopModelopenYamlOutputCursor(boolean printStartDocument, String name, String indent, boolean closeDestination, Object destination, GloopExecutionContext context)Return a Gloop output cursor for writing a large amount of YAML data.static voidprintYaml(IndentPrinter printer, GloopObject gloopObject, boolean includeNulls)Marshals a Gloop object to a YAML string.static GloopObjectreaderToGloopObject(Reader yamlString)Unmarshal a YAML string from aReaderto a Gloop object.static voidwriteYaml(Writer writer, GloopObject gloopObject, boolean includeNulls)Marshals a Gloop object to a YAML string.static GloopObjectyamlStringToGloopObject(String yamlString)Unmarshal a YAML string to a Gloop object.
-
-
-
Method Detail
-
gloopModelToYamlString
@GloopParameter(name="gloopYaml") public static String gloopModelToYamlString(GloopObject gloopObject)
Marshals a Gloop object to a YAML string.
- Parameters:
gloopObject- the object to marshall- Returns:
- YAML string representation of the object
- Since:
- 1.0
-
yamlStringToGloopObject
public static GloopObject yamlStringToGloopObject(String yamlString)
Unmarshal a YAML string to a Gloop object.
- Parameters:
yamlString- YAML to convert- Returns:
- Gloop object representation of the YAML string
- Since:
- 1.0
-
inputStreamToGloopObject
public static GloopObject inputStreamToGloopObject(InputStream yamlStream)
Unmarshal a YAML stream to a Gloop object.
- Parameters:
yamlStream- YAML to convert- Returns:
- Gloop object representation of the YAML stream
- Since:
- 1.0
-
readerToGloopObject
public static GloopObject readerToGloopObject(Reader yamlString)
Unmarshal a YAML string from a
Readerto a Gloop object.- Parameters:
yamlString- reader containing the YAML to convert- Returns:
- Gloop object representation of the YAML string
- Since:
- 1.0
-
asYaml
public static String asYaml(@GloopParameter(allowNull=false) GloopObject gloopObject, @GloopParameter(defaultValue="false") boolean includeRoot, @GloopParameter(defaultValue="false") boolean includeNulls)
Marshals a Gloop object to a YAML string.
- Parameters:
gloopObject- the object to marshalincludeRoot- whether or not to add a root element for the objectincludeNulls- whether or not to include null properties- Returns:
- YAML string representation of the object
- Since:
- 1.0
-
writeYaml
public static void writeYaml(@GloopParameter(allowNull=false) Writer writer, @GloopParameter(allowNull=false) GloopObject gloopObject, @GloopParameter(defaultValue="false") boolean includeNulls)
Marshals a Gloop object to a YAML string.
- Parameters:
writer- where the YAML string will be written togloopObject- the object to marshalincludeNulls- whether or not to include null properties- Since:
- 1.0
-
printYaml
public static void printYaml(@GloopParameter(allowNull=false) IndentPrinter printer, @GloopParameter(allowNull=false) GloopObject gloopObject, @GloopParameter(defaultValue="false") boolean includeNulls)
Marshals a Gloop object to a YAML string.
- Parameters:
printer- where the YAML string will be written togloopObject- the object to marshalincludeNulls- whether or not to include null properties- Since:
- 1.0
-
getInputCursorFromFile
@GloopObjectParameter("gloopYamlCursor{\n gloopYamlCursor[]{\n nodeName\n cursorRecord:object\n }\n}") public static GloopCursor getInputCursorFromFile(String filename, List<String> yamlNodeNames, GloopExecutionContext context) throws FileNotFoundException
Return a Gloop input cursor for reading the entries of a large YAML file.
Use the
yamlNodeNamesproperty to specify which nodes you want to extract from the YAML file. Use $yamlRoot for root arrays.- Parameters:
filename- the name of the large XML file to readyamlNodeNames- the element names the cursor should be seekingcontext- the Gloop execution context (automatically mapped by Gloop)- Returns:
- an input cursor that can iterate over all elements found in the XML,
where the element names are in the
yamlNodeNamesparameter - Throws:
FileNotFoundException- if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading- Since:
- 1.0
-
getInputCursorFromInputStream
@GloopObjectParameter("gloopYamlCursor{\n gloopYamlCursor[]{\n nodeName\n cursorRecord:object\n }\n}") public static GloopCursor getInputCursorFromInputStream(InputStream inputStream, List<String> yamlNodeNames, GloopExecutionContext context)
Return a Gloop input cursor for reading the entries of a large YAML stream.
Use the
yamlNodeNamesproperty to specify which nodes you want to extract from the YAML stream. Use $yamlRoot for root arrays.- Parameters:
inputStream- input stream containing the YAML to readyamlNodeNames- the element names the cursor should be seekingcontext- the Gloop execution context (automatically mapped by Gloop)- Returns:
- an input cursor that can iterate over all elements found in the XML,
where the element names are in the
yamlNodeNamesparameter - Since:
- 1.0
-
openYamlOutputCursor
@GloopObjectParameter("output{\nyamlCursorOutput{\nindentPrinter:object:printer used to write the yaml out to::::groovy.util.IndentPrinter\nyamlOutputCursor[]*{\n}\n}\n}") public static GloopModel openYamlOutputCursor(@GloopParameter(defaultValue="true") boolean printStartDocument, String name, @GloopParameter(allowNull=false,defaultValue=" ") String indent, @GloopParameter(defaultValue="true") boolean closeDestination, Object destination, GloopExecutionContext context) throws IOException
Return a Gloop output cursor for writing a large amount of YAML data.
- Parameters:
printStartDocument- set to true if the cursor will print a --- at the start of the documentname- name to print before declaring the array; should be null if there is no nameindent- indent to use if pretty printing; default is 2 spacescloseDestination- set to true if the cursor will close the underlying destination after printing closing textdestination- where to write the data to; must be aStringBuffer,Writer,OutputStream,Path, orFilecontext- the Gloop execution context (automatically mapped by Gloop)- Returns:
- an output cursor that can be used to add Gloop objects to for writing to YAML
- Throws:
IOException- Since:
- 1.0
-
-