Class YamlMethods


  • public final class YamlMethods
    extends Object
    Contains one-liners for reading and writing to YAML.
    • Constructor Detail

      • YamlMethods

        YamlMethods()
    • 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 Reader to 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 marshal
        includeRoot - whether or not to add a root element for the object
        includeNulls - whether or not to include null properties
        Returns:
        YAML string representation of the object
        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 yamlNodeNames property 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 read
        yamlNodeNames - the element names the cursor should be seeking
        context - 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 yamlNodeNames parameter
        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 yamlNodeNames property 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 read
        yamlNodeNames - the element names the cursor should be seeking
        context - 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 yamlNodeNames parameter
        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 document
        name - name to print before declaring the array; should be null if there is no name
        indent - indent to use if pretty printing; default is 2 spaces
        closeDestination - set to true if the cursor will close the underlying destination after printing closing text
        destination - where to write the data to; must be a StringBuffer, Writer, OutputStream, Path, or File
        context - 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