Class FlatFileMethods


  • public final class FlatFileMethods
    extends Object
    Provides one-liners for reading and writing flat files.
    • Constructor Detail

      • FlatFileMethods

        FlatFileMethods()
    • Method Detail

      • getFlatFileInputCursor

        public static GloopCursor getFlatFileInputCursor​(InputStream flatFileData,
                                                         String flatFileDescriptorName,
                                                         GloopExecutionContext context)
                                                  throws GloopException
        Return a Gloop cursor that's used to read in a flat file.
        Parameters:
        flatFileData - the flat file data that will be read
        flatFileDescriptorName - the namespace of the flat file descriptor
        context - the Gloop execution context (automatically mapped by Gloop)
        Returns:
        a Gloop cursor that can be used to iterate over the records in the flat file
        Throws:
        GloopException - when a cursor cannot be produced
        Since:
        1.0
      • getDelimitedFileInputCursor

        public static GloopCursor getDelimitedFileInputCursor​(InputStream flatFileData,
                                                              @GloopParameter(defaultValue="UTF-8")
                                                              String encoding,
                                                              @GloopParameter(defaultValue=",")
                                                              char delimiter,
                                                              Character quoteCharacter,
                                                              Character commentCharacter,
                                                              Character escapeCharacter,
                                                              @GloopParameter(defaultValue="0")
                                                              int firstRow,
                                                              @GloopParameter(defaultValue="false")
                                                              boolean ignoreSurroundingSpaces,
                                                              @GloopParameter(defaultValue="false")
                                                              boolean allowMissingColumnNames,
                                                              @GloopParameter(defaultValue="false")
                                                              boolean ignoreEmptyLines,
                                                              String nullString,
                                                              String modelReferenceName,
                                                              GloopModel modelTemplate,
                                                              String[] fieldNames,
                                                              @GloopParameter(defaultValue="\n")
                                                              String recordSeparator,
                                                              GloopExecutionContext context)
        Return a Gloop cursor that's used to read in a delimited flat file.
        Parameters:
        flatFileData - the flat file data that will be read
        encoding - the encoding to be used; default is UTF-8
        delimiter - the column delimiter; default is ,
        quoteCharacter - the the quote character to use to use
        commentCharacter - character used to signify the start of a comment; if null, commenting is disabled
        escapeCharacter - character used to escape other characters
        firstRow - the 0-based index that signifies the first data row of the input
        ignoreSurroundingSpaces - flag for ignoring spaces around column values; if true, column values will be trimmed
        allowMissingColumnNames - whether or not missing column names are allowed when parsing the header line
        ignoreEmptyLines - if true, empty lines will be ignored
        nullString - a string signifying what a null value is
        modelReferenceName - a namespace to a model that is used to determine what the model of the cursor will look like
        modelTemplate - An existing model used to determine what the model of the cursor will look like. The value of the model should not be null. To ensure the model is non-null, the model should not be an array, and should have at least one property that has a non-null value.
        fieldNames - a string array of the flat file's field names; used to create a Gloop model with the given names as its properties
        recordSeparator - the character signifying the end of a record; default is \n
        context - the Gloop execution context (automatically mapped by Gloop)
        Returns:
        a Gloop cursor that can be used to iterate over the records in the flat file
        Since:
        1.0
      • getFixedWidthFileInputCursor

        public static GloopCursor getFixedWidthFileInputCursor​(InputStream flatFileData,
                                                               @GloopParameter(defaultValue="UTF-8")
                                                               String encoding,
                                                               @GloopParameter(defaultValue="\n")
                                                               String recordSeparator,
                                                               @GloopParameter(defaultValue=" ")
                                                               char paddingCharacter,
                                                               @GloopParameter(defaultValue="true")
                                                               boolean leftJustified,
                                                               int[] widths,
                                                               @GloopParameter(defaultValue="0")
                                                               int firstDataRow,
                                                               String modelReferenceName,
                                                               GloopModel modelTemplate,
                                                               String[] fieldNames,
                                                               GloopExecutionContext context)
        Return a Gloop cursor that's used to read in a fixed-width flat file.
        Parameters:
        flatFileData - the flat file data that will be read
        encoding - the encoding to be used; default is UTF-8
        recordSeparator - a character signifying the end of a record; default is \n
        paddingCharacter - a character that's used to pad columns; default value is space
        leftJustified - specifies whether or not the values are left-justified; default is true
        widths - an array of column widths to use
        firstDataRow - the 0-based index that signifies the first data row of the input
        modelReferenceName - a namespace to a model that is used to determine what the model of the cursor will look like
        modelTemplate - An existing model used to determine what the model of the cursor will look like. The value of the model should not be null. To ensure the model is non-null, the model should not be an array, and should have at least one property that has a non-null value.
        fieldNames - a string array of the flat file's field names; used to create a Gloop model with the given names as its properties
        context - the Gloop execution context (automatically mapped by Gloop)
        Returns:
        a Gloop cursor that can be used to iterate over the records in the flat file
        Since:
        1.0
      • getExcelFileInputCursor

        public static GloopCursor getExcelFileInputCursor​(InputStream flatFileData,
                                                          @GloopParameter(defaultValue="0")
                                                          int sheetNumber,
                                                          @GloopParameter(defaultValue="0")
                                                          int firstDataRow,
                                                          String modelReferenceName,
                                                          GloopModel modelTemplate,
                                                          String[] fieldNames,
                                                          GloopExecutionContext context)
        Return a Gloop cursor that's used to read in an Excel file.
        Parameters:
        flatFileData - the Excel file that will be read
        sheetNumber - the sheet to process; default is 0; a value of -1 will process all sheets
        firstDataRow - the 0-based index that signifies the first data row of the input; default is 0
        modelReferenceName - a namespace to a model that is used to determine what the model of the cursor will look like
        modelTemplate - An existing model used to determine what the model of the cursor will look like. The value of the model should not be null. To ensure the model is non-null, the model should not be an array, and should have at least one property that has a non-null value.
        fieldNames - a string array of the flat file's field names; used to create a Gloop model with the given names as its properties
        context - the Gloop execution context (automatically mapped by Gloop)
        Returns:
        a Gloop cursor that can be used to iterate over the records in the Excel file
        Since:
        1.0
      • getFlatFileOutputCursor

        public static GloopCursor getFlatFileOutputCursor​(OutputStream flatFileData,
                                                          String flatFileDescriptorName,
                                                          GloopExecutionContext context)
        Return a Gloop cursor that's used to write to a flat file.
        Parameters:
        flatFileData - the output stream where data will be written to
        flatFileDescriptorName - the namespace of the flat file descriptor
        context - the Gloop execution context (automatically mapped by Gloop)
        Returns:
        a Gloop cursor that can be used to write the data to
        Since:
        1.0
      • getDelimitedFileOutputCursor

        public static GloopCursor getDelimitedFileOutputCursor​(OutputStream flatFileData,
                                                               @GloopParameter(defaultValue="UTF-8")
                                                               String encoding,
                                                               @GloopParameter(defaultValue=",")
                                                               char delimiter,
                                                               Character quoteCharacter,
                                                               @GloopParameter(defaultValue="All",choices={"All","Minimal","Non Numeric","None"})
                                                               String quoteMode,
                                                               Character escapeCharacter,
                                                               String nullString,
                                                               String modelReferenceName,
                                                               GloopModel modelTemplate,
                                                               String[] fieldNames,
                                                               @GloopParameter(defaultValue="\n")
                                                               String recordSeparator,
                                                               @GloopParameter(defaultValue="true")
                                                               boolean writeHeaderRecord,
                                                               GloopExecutionContext context)
        Return a Gloop cursor that's used to write to a delimited flat file.
        Parameters:
        flatFileData - the output stream where data will be written to
        encoding - the encoding to be used; default is UTF-8
        delimiter - the column delimiter; default is ,
        quoteCharacter - the quote character to use
        quoteMode - Tells the cursor how to quote column values. Choices are: All, Minimal, Non Numeric, and None.
        • All - quotes all columns.
        • Minimal - quotes fields which contain special characters such as a delimiter, the quote character to use, or any of the characters in line separator.
        • Non Numeric - quotes all non-numeric fields.
        • None - Never quote fields. When the delimiter occurs in data, it is preceded by the current escape character. If the escape character is not set, printing will throw an exception if any characters that require escaping are encountered.
        escapeCharacter - character used to escape other characters
        nullString - a string signifying what a null value is
        modelReferenceName - a namespace to a model that is used to determine what the model of the cursor will look like
        modelTemplate - An existing model used to determine what the model of the cursor will look like. The value of the model should not be null. To ensure the model is non-null, the model should not be an array, and should have at least one property that has a non-null value.
        fieldNames - a string array of the flat file's field names; used to create a Gloop model with the given names as its properties
        recordSeparator - a character signifying the end of a record; default is \n
        writeHeaderRecord - if true, a header record containing the column names will be written
        context - the Gloop execution context (automatically mapped by Gloop)
        Returns:
        a Gloop cursor that can be used to iterate over the records in the flat file
        Since:
        1.0
      • getFixedWidthOutputCursor

        public static GloopCursor getFixedWidthOutputCursor​(OutputStream flatFileData,
                                                            @GloopParameter(defaultValue="UTF-8")
                                                            String encoding,
                                                            int[] widths,
                                                            @GloopParameter(defaultValue="\n")
                                                            String recordSeparator,
                                                            @GloopParameter(defaultValue=" ")
                                                            char paddingCharacter,
                                                            String modelReferenceName,
                                                            GloopModel modelTemplate,
                                                            String[] fieldNames,
                                                            @GloopParameter(defaultValue="true")
                                                            boolean leftJustified,
                                                            @GloopParameter(defaultValue="true")
                                                            boolean writeHeaderRecord,
                                                            GloopExecutionContext context)
        Return a Gloop cursor that's used to write to a fixed-width flat file.
        Parameters:
        flatFileData - the output stream where data will be written to
        encoding - the encoding to be used; default is UTF-8
        widths - an array of column widths to use
        recordSeparator - a character signifying the end of a record; default is \n
        paddingCharacter - a character that's used to pad columns; default value is space
        modelReferenceName - a namespace to a model that is used to determine what the model of the cursor will look like
        modelTemplate - An existing model used to determine what the model of the cursor will look like. The value of the model should not be null. To ensure the model is non-null, the model should not be an array, and should have at least one property that has a non-null value.
        fieldNames - a string array of the flat file's field names; used to create a Gloop model with the given names as its properties
        leftJustified - specifies whether or not the values are left-justified; default is true
        writeHeaderRecord - if true, a header record containing the column names will be written
        context - the Gloop execution context (automatically mapped by Gloop)
        Returns:
        a Gloop cursor that can be used to write the data to
        Since:
        1.0
      • getExcelFileOutputCursor

        public static GloopCursor getExcelFileOutputCursor​(OutputStream flatFileData,
                                                           String modelReferenceName,
                                                           GloopModel modelTemplate,
                                                           String[] fieldNames,
                                                           @GloopParameter(defaultValue="true")
                                                           boolean writeHeaderRecord,
                                                           GloopExecutionContext context)
        Return a Gloop cursor that's used to write to an Excel file.
        Parameters:
        flatFileData - the output stream where data will be written to
        modelReferenceName - a namespace to a model that is used to determine what the model of the cursor will look like
        modelTemplate - An existing model used to determine what the model of the cursor will look like. The value of the model should not be null. To ensure the model is non-null, the model should not be an array, and should have at least one property that has a non-null value.
        fieldNames - a string array of the flat file's field names; used to create a Gloop model with the given names as its properties
        writeHeaderRecord - if true, a header record containing the column names will be written
        context - the Gloop execution context (automatically mapped by Gloop)
        Returns:
        a Gloop cursor that can be used to write the data to
        Since:
        1.0