Package io.toro.martini
Class FlatFileMethods
- java.lang.Object
-
- io.toro.martini.FlatFileMethods
-
public final class FlatFileMethods extends Object
Provides one-liners for reading and writing flat files.
-
-
Constructor Summary
Constructors Constructor Description FlatFileMethods()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static GloopCursor
getDelimitedFileInputCursor(InputStream flatFileData, String encoding, char delimiter, Character quoteCharacter, Character commentCharacter, Character escapeCharacter, int firstRow, boolean ignoreSurroundingSpaces, boolean allowMissingColumnNames, boolean ignoreEmptyLines, String nullString, String modelReferenceName, GloopModel modelTemplate, String[] fieldNames, String recordSeparator, GloopExecutionContext context)
Return a Gloop cursor that's used to read in a delimited flat file.static GloopCursor
getDelimitedFileOutputCursor(OutputStream flatFileData, String encoding, char delimiter, Character quoteCharacter, String quoteMode, Character escapeCharacter, String nullString, String modelReferenceName, GloopModel modelTemplate, String[] fieldNames, String recordSeparator, boolean writeHeaderRecord, GloopExecutionContext context)
Return a Gloop cursor that's used to write to a delimited flat file.static GloopCursor
getExcelFileInputCursor(InputStream flatFileData, int sheetNumber, int firstDataRow, String modelReferenceName, GloopModel modelTemplate, String[] fieldNames, GloopExecutionContext context)
Return a Gloop cursor that's used to read in an Excel file.static GloopCursor
getExcelFileOutputCursor(OutputStream flatFileData, String modelReferenceName, GloopModel modelTemplate, String[] fieldNames, boolean writeHeaderRecord, GloopExecutionContext context)
Return a Gloop cursor that's used to write to an Excel file.static GloopCursor
getFixedWidthFileInputCursor(InputStream flatFileData, String encoding, String recordSeparator, char paddingCharacter, boolean leftJustified, int[] widths, 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.static GloopCursor
getFixedWidthOutputCursor(OutputStream flatFileData, String encoding, int[] widths, String recordSeparator, char paddingCharacter, String modelReferenceName, GloopModel modelTemplate, String[] fieldNames, boolean leftJustified, boolean writeHeaderRecord, GloopExecutionContext context)
Return a Gloop cursor that's used to write to a fixed-width flat file.static GloopCursor
getFlatFileInputCursor(InputStream flatFileData, FlatFileDescriptor flatFileDescriptor, GloopExecutionContext context)
static GloopCursor
getFlatFileInputCursor(InputStream flatFileData, String flatFileDescriptorName, GloopExecutionContext context)
Return a Gloop cursor that's used to read in a flat file.static GloopCursor
getFlatFileOutputCursor(OutputStream flatFileData, String flatFileDescriptorName, GloopExecutionContext context)
Return a Gloop cursor that's used to write to a flat file.
-
-
-
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 readflatFileDescriptorName
- the namespace of the flat file descriptorcontext
- 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
-
getFlatFileInputCursor
public static GloopCursor getFlatFileInputCursor(InputStream flatFileData, FlatFileDescriptor flatFileDescriptor, GloopExecutionContext context)
-
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 readencoding
- the encoding to be used; default is UTF-8delimiter
- the column delimiter; default is ,quoteCharacter
- the the quote character to use to usecommentCharacter
- character used to signify the start of a comment; ifnull
, commenting is disabledescapeCharacter
- character used to escape other charactersfirstRow
- the 0-based index that signifies the first data row of the inputignoreSurroundingSpaces
- flag for ignoring spaces around column values; iftrue
, column values will be trimmedallowMissingColumnNames
- whether or not missing column names are allowed when parsing the header lineignoreEmptyLines
- iftrue
, empty lines will be ignorednullString
- a string signifying what anull
value ismodelReferenceName
- a namespace to a model that is used to determine what the model of the cursor will look likemodelTemplate
- An existing model used to determine what the model of the cursor will look like. The value of the model should not benull
. 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 propertiesrecordSeparator
- the character signifying the end of a record; default is \ncontext
- 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 readencoding
- the encoding to be used; default is UTF-8recordSeparator
- a character signifying the end of a record; default is \npaddingCharacter
- a character that's used to pad columns; default value is spaceleftJustified
- specifies whether or not the values are left-justified; default istrue
widths
- an array of column widths to usefirstDataRow
- the 0-based index that signifies the first data row of the inputmodelReferenceName
- a namespace to a model that is used to determine what the model of the cursor will look likemodelTemplate
- An existing model used to determine what the model of the cursor will look like. The value of the model should not benull
. 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 propertiescontext
- 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 readsheetNumber
- the sheet to process; default is 0; a value of -1 will process all sheetsfirstDataRow
- the 0-based index that signifies the first data row of the input; default is 0modelReferenceName
- a namespace to a model that is used to determine what the model of the cursor will look likemodelTemplate
- An existing model used to determine what the model of the cursor will look like. The value of the model should not benull
. 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 propertiescontext
- 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 toflatFileDescriptorName
- the namespace of the flat file descriptorcontext
- 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 toencoding
- the encoding to be used; default is UTF-8delimiter
- the column delimiter; default is ,quoteCharacter
- the quote character to usequoteMode
- 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 charactersnullString
- a string signifying what anull
value ismodelReferenceName
- a namespace to a model that is used to determine what the model of the cursor will look likemodelTemplate
- An existing model used to determine what the model of the cursor will look like. The value of the model should not benull
. 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 propertiesrecordSeparator
- a character signifying the end of a record; default is \nwriteHeaderRecord
- iftrue
, a header record containing the column names will be writtencontext
- 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 toencoding
- the encoding to be used; default is UTF-8widths
- an array of column widths to userecordSeparator
- a character signifying the end of a record; default is \npaddingCharacter
- a character that's used to pad columns; default value is spacemodelReferenceName
- a namespace to a model that is used to determine what the model of the cursor will look likemodelTemplate
- An existing model used to determine what the model of the cursor will look like. The value of the model should not benull
. 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 propertiesleftJustified
- specifies whether or not the values are left-justified; default istrue
writeHeaderRecord
- iftrue
, a header record containing the column names will be writtencontext
- 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 tomodelReferenceName
- a namespace to a model that is used to determine what the model of the cursor will look likemodelTemplate
- An existing model used to determine what the model of the cursor will look like. The value of the model should not benull
. 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 propertieswriteHeaderRecord
- iftrue
, a header record containing the column names will be writtencontext
- the Gloop execution context (automatically mapped by Gloop)- Returns:
- a Gloop cursor that can be used to write the data to
- Since:
- 1.0
-
-