Package com.univocity.parsers.common
Class AbstractWriter<S extends CommonWriterSettings<?>>
java.lang.Object
com.univocity.parsers.common.AbstractWriter<S>
- Type Parameters:
S- The specific writer settings configuration class, which can potentially provide additional configuration options supported by the writer implementation.
- Direct Known Subclasses:
CsvWriter,FixedWidthWriter,TsvWriter
The AbstractWriter class provides a common ground for all writers in univocity-parsers.
It handles all settings defined by
CommonWriterSettings, and delegates the writing algorithm implementation to its subclasses through the abstract
method processRow(Object[])
The following (absolutely required) attributes are exposed to subclasses:
- appender (
WriterCharAppender): the character writer that appends characters from a given input into an internal buffer
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final WriterCharAppenderprivate final booleanprotected final charprivate NormalizedString[]protected final Stringprivate booleanprivate final intprotected booleanprivate Map<NormalizedString[], Map<NormalizedString, Integer>> protected NormalizedString[]protected boolean[]protected booleanprotected booleanprivate int[]private final CommonSettings<DummyFormat> private final booleanprivate intprivate final char[]protected final Stringprivate Object[]private final Object[]private intprotected longprivate final WriterCharAppenderprivate final booleanprotected booleanprivate booleanprotected final intprivate Writerprivate final RowWriterProcessorprotected boolean -
Constructor Summary
ConstructorsConstructorDescriptionAbstractWriter(File file, String encoding, S settings) All writers must support, at the very least, the settings provided byCommonWriterSettings.AbstractWriter(File file, Charset encoding, S settings) All writers must support, at the very least, the settings provided byCommonWriterSettings.AbstractWriter(File file, S settings) All writers must support, at the very least, the settings provided byCommonWriterSettings.AbstractWriter(OutputStream output, String encoding, S settings) All writers must support, at the very least, the settings provided byCommonWriterSettings.AbstractWriter(OutputStream output, Charset encoding, S settings) All writers must support, at the very least, the settings provided byCommonWriterSettings.AbstractWriter(OutputStream output, S settings) All writers must support, at the very least, the settings provided byCommonWriterSettings.AbstractWriter(Writer writer, S settings) All writers must support, at the very least, the settings provided byCommonWriterSettings.AbstractWriter(S settings) All writers must support, at the very least, the settings provided byCommonWriterSettings. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddStringValues(Collection<String> values) Writes a sequence of Strings to a row in memory.final voidWrites a value to a row in memory.private final voidaddValue(NormalizedString[] headersInContext, NormalizedString headerName, boolean ignoreOnMismatch, Object value) final voidWrites a value to a row in memory.final voidWrites a value to a row in memory.final voidWrites a sequence of values to a row in memory.final voidaddValues(Collection<?> values) Writes a sequence of values to a row in memory.private Object[]adjustRowLength(Object[] row) protected final booleanallowTrim(int fieldIndex) Checks whether the writer can remove trailing/leading whitespaces from a value being written.protected final voidappendToRow(char ch) Appends the given character to the output row.protected final voidappendToRow(char[] chars) Appends the given character sequence to the output rowprotected final voidAppends the processed sequence of characters inappenderto the output row.final voidclose()Closes theWritergiven in this class constructor.final voidcommentRow(String comment) Writes a comment row to the output.final StringcommentRowToString(String comment) Writes a comment row to aStringfinal voidDiscards the contents written to the internal in-memory row (usingor #writeValue().protected voidenableNewlineAfterRecord(boolean enableNewlineAfterRecord) protected Object[]private <T> voidfillOutputRow(T[] row) Used when fields were selected and the input rows have a different order than the output.private voidfinal voidflush()Flushes theWritergiven in this class constructor.private StringgetContent(CharSequence tmp) private Object[]getContent(Object[] tmp) private intgetFieldIndex(NormalizedString[] headersInContext, NormalizedString headerName, boolean ignoreOnMismatch) Calculates the index of a header name in relation to the originalheadersarray defined in this writerfinal longReturns the number of records written to the output so farprivate NormalizedString[]protected StringgetStringValue(Object element) Converts a given object to its String representation for writing to aStringIf the object is null, thennullValueis returned. If the String representation of this object is an empty String, thenemptyValueis returnedprotected abstract voidinitialize(S settings) Initializes the concrete implementation of this class with format-specific settings.private voidWrites the accumulated value of a record to the output, followed by a newline, and increases the record count.private StringWrites the accumulated value of a record to the output, followed by a newline, and increases the record count.final <K> voidprocessObjectRecords(Map<K, String> headerMapping, Map<K, Object[]> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes all values to the output .final <K> voidprocessObjectRecordsAndClose(Map<K, Object[]> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes all values to the output and closes the writer.final <K> voidprocessObjectRecordsAndClose(Map<K, String> headerMapping, Map<K, Object[]> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes all values to the output and closes the writer.processObjectRecordsToString(Map<K, Object[]> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result into aListofStringformatted to according to the specified output format.processObjectRecordsToString(Map<K, String> headerMapping, Map<K, Object[]> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result into aListofStringformatted to according to the specified output format.final voidprocessRecord(Object record) Processes the data given for an individual record with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes it.final voidprocessRecord(Object... record) Processes the data given for an individual record with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes it.final voidprocessRecord(Map<?, ?> rowData) Processes the values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result into a new output record ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().final <K> voidprocessRecord(Map<K, String> headerMapping, Map<K, ?> rowData) Processes the values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result into a new output record ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().final <T extends Record>
voidprocessRecord(T record) final voidprocessRecords(Iterable<?> records) Iterates over all records, processes each one with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), and writes them.final voidprocessRecords(Object[] records) Iterates over all records, processes each one with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), and writes them.final <K,I extends Iterable<?>>
voidprocessRecords(Map<K, I> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes all values to the output .final <K,I extends Iterable<?>>
voidprocessRecords(Map<K, String> headerMapping, Map<K, I> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes all values to the output .final <T extends Record>
voidprocessRecords(T[] records) Iterates over all records, processes each one with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), and writes them.final voidprocessRecordsAndClose(Iterable<?> allRecords) Iterates over all records, processes each one with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), and writes them, then finally and closes the output ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().final voidprocessRecordsAndClose(Object[] allRecords) Iterates over all records, processes each one with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), and writes them, then finally and closes the output ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().final <K,I extends Iterable<?>>
voidprocessRecordsAndClose(Map<K, I> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes all values to the output and closes the writer.final <K,I extends Iterable<?>>
voidprocessRecordsAndClose(Map<K, String> headerMapping, Map<K, I> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes all values to the output and closes the writer.processRecordsToString(Iterable<?> records) Iterates over all records, processes each one with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), and writes them to aListofString.processRecordsToString(Object[] records) Iterates over all records, processes each one with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), and writes them them to aListofString.processRecordsToString(Map<K, I> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result into aListofStringformatted to according to the specified output format.processRecordsToString(Map<K, String> headerMapping, Map<K, I> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result into aListofStringformatted to according to the specified output format.final StringprocessRecordToString(Object record) Processes the data given for an individual record with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes it.final StringprocessRecordToString(Object... record) Processes the data given for an individual record with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes it to aString.final StringprocessRecordToString(Map<?, ?> rowData) Processes the values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result intoStringformatted according to the specified output format.final <K> StringprocessRecordToString(Map<K, String> headerMapping, Map<K, ?> rowData) Processes the values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result intoStringformatted according to the specified output format.processRecordToString(T record) Processes the data given for an individual record with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes it to aString.protected abstract voidprocessRow(Object[] row) Format-specific implementation for writing a single record into the output.final voidWrites the contents accumulated in an internal in-memory row (usingor #addValue()to a new record in the output.final StringWrites the contents accumulated in an internal in-memory row (usingor #addValue()to aStringThe objects added to this row will be processed with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor().private voidsetHeadersFromMap(Map<?, ?> map, boolean keys) Iterates over the keys of a map and builds an internal header row.protected static intskipLeadingWhitespace(int whitespaceRangeStart, String element) Identifies the starting character index of a value being written if leading whitespaces are to be discarded.private voidSubmits a row for processing by the format-specific implementation.private TextWritingExceptionthrowExceptionAndClose(String message) In case of any exceptions, aTextWritingExceptionis thrown, and the outputWriteris closed.private TextWritingExceptionthrowExceptionAndClose(String message, Object[] recordValues, Throwable cause) In case of any exceptions, aTextWritingExceptionis thrown, and the outputWriteris closed.private TextWritingExceptionthrowExceptionAndClose(String message, String recordCharacters, Throwable cause) In case of any exceptions, aTextWritingExceptionis thrown, and the outputWriteris closed.private TextWritingExceptionthrowExceptionAndClose(String message, Throwable cause) In case of any exceptions, aTextWritingExceptionis thrown, and the outputWriteris closed.voidupdateFieldExclusion(Integer... fieldIndexesToExclude) Updates the selection of fields to exclude when writing.voidupdateFieldExclusion(String... fieldsToExclude) Updates the selection of fields to exclude when writing.voidupdateFieldSelection(Integer... newFieldSelectionByIndex) Updates the selection of fields to write.voidupdateFieldSelection(String... newFieldSelection) Updates the selection of fields to write.private voidupdateIndexesToWrite(CommonSettings<?> settings) Update indexes to write based on the field selection provided by the user.wrapObjectArray(Map<K, Object[]> rowData) wrapRecordValues(Map<K, ? extends Record> rowData) wrapStringArray(Map<K, String[]> rowData) final voidWrites an empty line to the output, unless this is aFixedWidthWriterwhoseFixedWidthWriterSettings.getWriteLineSeparatorAfterRecord()evaluates tofalse.final voidWrites the headers defined inCommonSettings.getHeaders()ATextWritingExceptionwill be thrown if no headers were defined or if records were already written to the output.final voidwriteHeaders(String... headers) Writes the given collection of headers to the output.final voidwriteHeaders(Collection<?> headers) Writes the given collection of headers to the output.final StringWrites the headers defined inCommonSettings.getHeaders()to aStringfinal StringwriteHeadersToString(String... headers) Writes the given collection of headers to aStringATextWritingExceptionwill be thrown if no headers were defined or if records were already written to aStringfinal StringwriteHeadersToString(Collection<?> headers) Writes the given collection of headers to aStringATextWritingExceptionwill be thrown if no headers were defined.final <K> voidwriteObjectRows(Map<K, String> headerMapping, Map<K, Object[]> rowData) Writes the values of a given map to multiple output records Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable.final <K> voidwriteObjectRowsAndClose(Map<K, Object[]> rowData) Writes the values of a given map to multiple output records and closes the output when finished.final <K> voidwriteObjectRowsAndClose(Map<K, String> headerMapping, Map<K, Object[]> rowData) Writes the values of a given map to multiple output records and closes the output when finished.writeObjectRowsToString(Map<K, String> headerMapping, Map<K, Object[]> rowData) Writes the values of a given map to aListofStringformatted to according to the specified output format.final <T extends Record>
voidwriteRecord(T row) Writes the data given for an individual record.final voidwriteRecords(Collection<? extends Record> rows) Iterates over all records and writes them to the output.final <K> voidwriteRecords(Map<K, String> headerMapping, Map<K, ? extends Record> rowData) Writes the values of a given map to multiple output records Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable.final voidwriteRecordsAndClose(Collection<? extends Record> allRows) Iterates over all records, writes them and closes the output.final <K> voidwriteRecordsAndClose(Map<K, ? extends Record> rowData) Writes the values of a given map to multiple output records and closes the output when finished.final <K> voidwriteRecordsAndClose(Map<K, String> headerMapping, Map<K, ? extends Record> rowData) Writes the values of a given map to multiple output records and closes the output when finished.writeRecordsToString(Collection<? extends Record> rows) Iterates over all records and writes them to aListofString.writeRecordsToString(Map<K, String> headerMapping, Map<K, ? extends Record> rowData) Writes the values of a given map to aListofStringformatted to according to the specified output format.writeRecordToString(T row) Writes the data given for an individual record to aString.final voidWrites the data given for an individual record.final voidWrites a plain (potentially free-text) String as a line to the output.final voidWrites the data given for an individual record.final voidwriteRow(Collection<?> row) Writes the data given for an individual record.final voidWrites the values of a given map into new output record Note this method will not use theRowWriterProcessor.final <K> voidWrites the values of a given map into new output record Note this method will not use theRowWriterProcessor.final <C extends Collection<?>>
voidIterates over all records and writes them to the output.final voidIterates over all records and writes them to the output.final voidwriteRows(Collection<Object[]> rows) Iterates over all records and writes them to the output.final <K,I extends Iterable<?>>
voidWrites the values of a given map to multiple output records Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable.final <K,I extends Iterable<?>>
voidWrites the values of a given map to multiple output records Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable.private <K,I extends Iterable<?>>
voidwriteRows(Map<K, String> headerMapping, Map<K, I> rowData, List<String> outputList, boolean useRowProcessor) Writes the values of a given map to aListofStringformatted to according to the specified output format.final <C extends Collection<?>>
voidwriteRowsAndClose(Iterable<C> allRows) Iterates over all records, writes them and closes the output.final voidwriteRowsAndClose(Object[][] allRows) Iterates over all records, writes them and closes the output.final voidwriteRowsAndClose(Collection<Object[]> allRows) Iterates over all records, writes them and closes the output.final <K,I extends Iterable<?>>
voidwriteRowsAndClose(Map<K, I> rowData) Writes the values of a given map to multiple output records and closes the output when finished.final <K,I extends Iterable<?>>
voidwriteRowsAndClose(Map<K, String> headerMapping, Map<K, I> rowData) Writes the values of a given map to multiple output records and closes the output when finished.final <C extends Collection<?>>
List<String> writeRowsToString(Iterable<C> rows) Iterates over all records and writes them to aListofString.writeRowsToString(Object[][] rows) Iterates over all records and writes them to aListofString.writeRowsToString(Collection<Object[]> rows) Iterates over all records and writes them to aListofString.writeRowsToString(Map<K, I> rowData) Writes the values of a given map to aListofStringformatted to according to the specified output format.writeRowsToString(Map<K, String> headerMapping, Map<K, I> rowData) Writes the values of a given map to aListofStringformatted to according to the specified output format.final StringwriteRowToString(Object... row) Writes the data given for an individual record to aString.final StringwriteRowToString(String[] row) Writes the data given for an individual record to aString.final StringwriteRowToString(Collection<?> row) Writes the data given for an individual record to aString.final StringwriteRowToString(Map<?, ?> rowData) Writes the values of a given map to aStringformatted to according to the specified output format.final <K> StringwriteRowToString(Map<K, String> headerMapping, Map<K, ?> rowData) Writes the values of a given map to aStringformatted to according to the specified output format.final <C extends Collection<?>>
voidwriteStringRows(Iterable<C> rows) Iterates over all records and writes them to the output.final voidwriteStringRows(Collection<String[]> rows) Iterates over all records and writes them to the output.final <K> voidwriteStringRows(Map<K, String> headerMapping, Map<K, String[]> rowData) Writes the values of a given map to multiple output records Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable.final voidwriteStringRowsAndClose(Collection<String[]> allRows) Iterates over all records, writes them and closes the output.final <K> voidwriteStringRowsAndClose(Map<K, String[]> rowData) Writes the values of a given map to multiple output records and closes the output when finished.final <K> voidwriteStringRowsAndClose(Map<K, String> headerMapping, Map<K, String[]> rowData) Writes the values of a given map to multiple output records and closes the output when finished.final <C extends Collection<?>>
List<String> writeStringRowsToString(Iterable<C> rows) Iterates over all records and writes them to aListofString.writeStringRowsToString(Collection<String[]> rows) Iterates over all records and writes them to aListofString.writeStringRowsToString(Map<K, String> headerMapping, Map<K, String[]> rowData) Writes the values of a given map to aListofStringformatted to according to the specified output format.private <K> voidwriteValuesFromMap(Map<K, String> headerMapping, Map<K, ?> rowData) Writes values from an implementation ofMapto a partial output record, ready to be written to the output.final voidWrites the contents accumulated in an internal in-memory row (usingor #writeValue()to a new record in the output.final StringWrites the contents accumulated in an internal in-memory row (usingor #addValue()as aString
-
Field Details
-
writerProcessor
-
writer
-
skipEmptyLines
private final boolean skipEmptyLines -
comment
protected final char comment -
rowAppender
-
isHeaderWritingEnabled
private final boolean isHeaderWritingEnabled -
outputRow
-
indexesToWrite
private int[] indexesToWrite -
lineSeparator
private final char[] lineSeparator -
headers
-
recordCount
protected long recordCount -
nullValue
-
emptyValue
-
appender
-
partialLine
-
partialLineIndex
private int partialLineIndex -
headerIndexes
-
largestRowLength
private int largestRowLength -
writingHeaders
protected boolean writingHeaders -
headerTrimFlags
protected boolean[] headerTrimFlags -
dummyHeaderRow
-
expandRows
protected boolean expandRows -
usingSwitch
private boolean usingSwitch -
enableNewlineAfterRecord
private boolean enableNewlineAfterRecord -
usingNullOrEmptyValue
protected boolean usingNullOrEmptyValue -
whitespaceRangeStart
protected final int whitespaceRangeStart -
columnReorderingEnabled
private final boolean columnReorderingEnabled -
ignoreLeading
protected boolean ignoreLeading -
ignoreTrailing
protected boolean ignoreTrailing -
internalSettings
-
errorContentLength
private final int errorContentLength
-
-
Constructor Details
-
AbstractWriter
All writers must support, at the very least, the settings provided byCommonWriterSettings. The AbstractWriter requires its configuration to be properly initialized. Important: by not providing an instance ofWriterto this constructor, only the operations that write to Strings are available.- Parameters:
settings- the writer configuration
-
AbstractWriter
All writers must support, at the very least, the settings provided byCommonWriterSettings. The AbstractWriter requires its configuration to be properly initialized.- Parameters:
file- the output file that will be written with the format-specific records as defined by subclasses ofAbstractWriter.settings- the writer configuration
-
AbstractWriter
All writers must support, at the very least, the settings provided byCommonWriterSettings. The AbstractWriter requires its configuration to be properly initialized.- Parameters:
file- the output file that will be written with the format-specific records as defined by subclasses ofAbstractWriter.encoding- the encoding of the filesettings- the writer configuration
-
AbstractWriter
All writers must support, at the very least, the settings provided byCommonWriterSettings. The AbstractWriter requires its configuration to be properly initialized.- Parameters:
file- the output file that will be written with the format-specific records as defined by subclasses ofAbstractWriter.encoding- the encoding of the filesettings- the writer configuration
-
AbstractWriter
All writers must support, at the very least, the settings provided byCommonWriterSettings. The AbstractWriter requires its configuration to be properly initialized.- Parameters:
output- the output stream that will be written with the format-specific records as defined by subclasses ofAbstractWriter.settings- the writer configuration
-
AbstractWriter
All writers must support, at the very least, the settings provided byCommonWriterSettings. The AbstractWriter requires its configuration to be properly initialized.- Parameters:
output- the output stream that will be written with the format-specific records as defined by subclasses ofAbstractWriter.encoding- the encoding of the streamsettings- the writer configuration
-
AbstractWriter
All writers must support, at the very least, the settings provided byCommonWriterSettings. The AbstractWriter requires its configuration to be properly initialized.- Parameters:
output- the output stream that will be written with the format-specific records as defined by subclasses ofAbstractWriter.encoding- the encoding of the streamsettings- the writer configuration
-
AbstractWriter
All writers must support, at the very least, the settings provided byCommonWriterSettings. The AbstractWriter requires its configuration to be properly initialized.- Parameters:
writer- the output resource that will receive the format-specific records as defined by subclasses ofAbstractWriter.settings- the writer configuration
-
-
Method Details
-
enableNewlineAfterRecord
protected void enableNewlineAfterRecord(boolean enableNewlineAfterRecord) -
initialize
Initializes the concrete implementation of this class with format-specific settings.- Parameters:
settings- the settings object specific to the format being written.
-
updateIndexesToWrite
Update indexes to write based on the field selection provided by the user. -
updateFieldSelection
Updates the selection of fields to write. This is useful if the input rows change during the writing process and their values need be allocated to specific columns.- Parameters:
newFieldSelection- the new selection of fields to write.
-
updateFieldSelection
Updates the selection of fields to write. This is useful if the input rows change during the writing process and their values need be allocated to specific columns.- Parameters:
newFieldSelectionByIndex- the new selection of fields to write.
-
updateFieldExclusion
Updates the selection of fields to exclude when writing. This is useful if the input rows change during the writing process and their values need be allocated to specific columns.- Parameters:
fieldsToExclude- the selection of fields to exclude from the output.
-
updateFieldExclusion
Updates the selection of fields to exclude when writing. This is useful if the input rows change during the writing process and their values need be allocated to specific columns.- Parameters:
fieldIndexesToExclude- the selection of fields to exclude from the output.
-
submitRow
Submits a row for processing by the format-specific implementation.- Parameters:
row- the data to be written for a single record in the output.
-
processRow
Format-specific implementation for writing a single record into the output. The AbstractWriter handles the initialization and processing of the output until it is ready to be written (generally, reorganizing it and passing it on to aRowWriterProcessor). It then delegates the record to the writer-specific implementation defined byprocessRow(Object[]). In general, an implementation ofprocessRow(Object[])will perform the following steps:- Iterate over each object in the given input and convert it to the expected String representation.
- The conversion must happen using the provided
appenderobject. The an individual value is processed, theappendValueToRow()method must be called. This will clear the accumulated value inappenderand add it to the output row. - Format specific separators and other characters must be introduced to the output row using
appendToRow(char)
processRow(Object[])method returns, a row will be written to the output with the processed information, and a newline will be automatically written after the given contents, unless this is aFixedWidthWriterwhoseFixedWidthWriterSettings.getWriteLineSeparatorAfterRecord()evaluates tofalse. The newline character sequence will conform to what is specified inFormat.getLineSeparator()This cycle repeats until the writing process is stopped by the user or an error happens. In case of errors, the unchecked exceptionTextWritingExceptionwill be thrown and all resources in use will be closed automatically. The exception should contain the cause and more information about the output state when the error happened.- Parameters:
row- the data to be written to the output in the expected format.- See Also:
-
appendValueToRow
protected final void appendValueToRow()Appends the processed sequence of characters inappenderto the output row. -
appendToRow
protected final void appendToRow(char ch) Appends the given character to the output row.- Parameters:
ch- the character to append to the output row
-
appendToRow
protected final void appendToRow(char[] chars) Appends the given character sequence to the output row- Parameters:
chars- the sequence of characters to append to the output row
-
writeHeaders
public final void writeHeaders()Writes the headers defined inCommonSettings.getHeaders()ATextWritingExceptionwill be thrown if no headers were defined or if records were already written to the output. -
writeHeaders
Writes the given collection of headers to the output. ATextWritingExceptionwill be thrown if no headers were defined or if records were already written to the output.- Parameters:
headers- the headers to write to the output.
-
writeHeaders
Writes the given collection of headers to the output. ATextWritingExceptionwill be thrown if no headers were defined or if records were already written to the output.- Parameters:
headers- the headers to write to the output.
-
processRecordsAndClose
Iterates over all records, processes each one with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), and writes them, then finally and closes the output ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Parameters:
allRecords- the records to be transformed by aRowWriterProcessorand then written to the output
-
processRecordsAndClose
Iterates over all records, processes each one with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), and writes them, then finally and closes the output ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Parameters:
allRecords- the records to be transformed by aRowWriterProcessorand then written to the output
-
processRecords
Iterates over all records, processes each one with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), and writes them. The output will remain open for further writing. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Parameters:
records- the records to be transformed by aRowWriterProcessorand then written to the output
-
processRecords
Iterates over all records, processes each one with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), and writes them. The output will remain open for further writing. * ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Parameters:
records- the records to transformed by aRowWriterProcessorand then written to the output
-
processRecords
Iterates over all records, processes each one with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), and writes them. The output will remain open for further writing. * ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
T- the concrete Record type- Parameters:
records- the records to transformed by aRowWriterProcessorand then written to the output
-
processRecord
Processes the data given for an individual record with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes it. The output will remain open for further writing. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Parameters:
record- the information of a single record to be transformed by aRowWriterProcessorand then written to the output
-
processRecord
-
processRecord
Processes the data given for an individual record with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes it. The output will remain open for further writing. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Parameters:
record- the information of a single record to be transformed by aRowWriterProcessorand then written to the output
-
getRowProcessorHeaders
-
writeRowsAndClose
Iterates over all records, writes them and closes the output. Note this method will not use theRowWriterProcessor. UseprocessRecordsAndClose(Iterable)for that.- Type Parameters:
C- Collection of objects containing values of a row- Parameters:
allRows- the rows to be written to the output
-
writeRowsAndClose
Iterates over all records, writes them and closes the output. Note this method will not use theRowWriterProcessor. UseprocessRecordsAndClose(Object[])for that.- Parameters:
allRows- the rows to be written to the output
-
writeStringRowsAndClose
Iterates over all records, writes them and closes the output. Note this method will not use theRowWriterProcessor. UseprocessRecordsAndClose(Iterable)for that.- Parameters:
allRows- the rows to be written to the output
-
writeRecordsAndClose
Iterates over all records, writes them and closes the output. Note this method will not use theRowWriterProcessor. UseprocessRecordsAndClose(Iterable)for that.- Parameters:
allRows- the rows to be written to the output
-
writeRowsAndClose
Iterates over all records, writes them and closes the output. Note this method will not use theRowWriterProcessor. UseprocessRecordsAndClose(Object[])for that.- Parameters:
allRows- the rows to be written to the output
-
writeRows
Iterates over all records and writes them to the output. The output will remain open for further writing. Note this method will not use theRowWriterProcessor. UseprocessRecords(Object[])for that.- Parameters:
rows- the rows to be written to the output
-
writeRows
Iterates over all records and writes them to the output. The output will remain open for further writing. Note this method will not use theRowWriterProcessor. UseprocessRecords(Iterable)for that.- Type Parameters:
C- Collection of objects containing values of a row- Parameters:
rows- the rows to be written to the output
-
writeStringRows
Iterates over all records and writes them to the output. The output will remain open for further writing. Note this method will not use theRowWriterProcessor. UseprocessRecords(Iterable)for that.- Parameters:
rows- the rows to be written to the output
-
writeRecords
Iterates over all records and writes them to the output. The output will remain open for further writing. Note this method will not use theRowWriterProcessor. UseprocessRecords(Iterable)for that.- Parameters:
rows- the rows to be written to the output
-
writeStringRows
Iterates over all records and writes them to the output. The output will remain open for further writing. Note this method will not use theRowWriterProcessor. UseprocessRecords(Iterable)for that.- Type Parameters:
C- Collection of objects containing values of a row- Parameters:
rows- the rows to be written to the output
-
writeRows
Iterates over all records and writes them to the output. The output will remain open for further writing. Note this method will not use theRowWriterProcessor. UseprocessRecords(Iterable)for that.- Parameters:
rows- the rows to be written to the output
-
writeRow
Writes the data given for an individual record. The output will remain open for further writing. Note this method will not use theRowWriterProcessor. UseprocessRecord(Object)for that.- Parameters:
row- the information of a single record to be written to the output
-
writeRow
Writes the data given for an individual record. The output will remain open for further writing. If the given data is null or empty, andCommonSettings.getSkipEmptyLines()is true, the input will be just ignored. IfCommonSettings.getSkipEmptyLines()is false, then an empty row will be written to the output (as specified bywriteEmptyRow()). In case of any errors, aTextWritingExceptionwill be thrown and theWritergiven in the constructor will be closed. Note this method will not use theRowWriterProcessor. UseprocessRecord(Object)for that.- Parameters:
row- the information of a single record to be written to the output
-
writeRecord
Writes the data given for an individual record. The output will remain open for further writing. If the given data is null or empty, andCommonSettings.getSkipEmptyLines()is true, the input will be just ignored. IfCommonSettings.getSkipEmptyLines()is false, then an empty row will be written to the output (as specified bywriteEmptyRow()). In case of any errors, aTextWritingExceptionwill be thrown and theWritergiven in the constructor will be closed. Note this method will not use theRowWriterProcessor. UseprocessRecord(Object)for that.- Type Parameters:
T- the concrete Record type- Parameters:
row- the information of a single record to be written to the output
-
writeRow
Writes the data given for an individual record. The output will remain open for further writing. If the given data is null or empty, andCommonSettings.getSkipEmptyLines()is true, the input will be just ignored. IfCommonSettings.getSkipEmptyLines()is false, then an empty row will be written to the output (as specified bywriteEmptyRow()). In case of any errors, aTextWritingExceptionwill be thrown and theWritergiven in the constructor will be closed. Note this method will not use theRowWriterProcessor. UseprocessRecord(Object)for that.- Parameters:
row- the information of a single record to be written to the output
-
expand
-
writeRow
Writes a plain (potentially free-text) String as a line to the output. A newline will automatically written after the given contents, unless this is aFixedWidthWriterwhoseFixedWidthWriterSettings.getWriteLineSeparatorAfterRecord()evaluates tofalse. The newline character sequence will conform to what is specified inFormat.getLineSeparator()The writer implementation has no control over the format of this content. The output will remain open for further writing.- Parameters:
row- the line to be written to the output
-
writeEmptyRow
public final void writeEmptyRow()Writes an empty line to the output, unless this is aFixedWidthWriterwhoseFixedWidthWriterSettings.getWriteLineSeparatorAfterRecord()evaluates tofalse. The newline character sequence will conform to what is specified inFormat.getLineSeparator()The output will remain open for further writing. -
commentRow
Writes a comment row to the output. A newline will automatically written after the given contents, unless this is aFixedWidthWriterwhoseFixedWidthWriterSettings.getWriteLineSeparatorAfterRecord()evaluates tofalse. The newline character sequence will conform to what is specified inFormat.getLineSeparator()The output will remain open for further writing.- Parameters:
comment- the contents to be written as a comment to the output
-
fillOutputRow
private <T> void fillOutputRow(T[] row) Used when fields were selected and the input rows have a different order than the output. This method fills the internal #outputRow array with the values provided by the user in the correct order.- Parameters:
row- user-provided data which has to be rearranged to the expected record sequence before writing to the output.
-
internalWriteRow
private void internalWriteRow()Writes the accumulated value of a record to the output, followed by a newline, and increases the record count. The newline character sequence will conform to what is specified inFormat.getLineSeparator()The contents ofrowAppenderdepend on the concrete implementation ofprocessRow(Object[]) -
skipLeadingWhitespace
Identifies the starting character index of a value being written if leading whitespaces are to be discarded. Implementation note whitespaces are considered all characters wherech <= ' 'evaluates totrue- Parameters:
whitespaceRangeStart- starting range after which characters will be considered whitespaceelement- the String to be scanned for leading whitespaces.- Returns:
- the index of the first non-whitespace character in the given element.
-
flush
public final void flush()Flushes theWritergiven in this class constructor. An IllegalStateException will be thrown in case of any errors, and the writer will be closed. -
close
public final void close()Closes theWritergiven in this class constructor. An IllegalStateException will be thrown in case of any errors. -
throwExceptionAndClose
In case of any exceptions, aTextWritingExceptionis thrown, and the outputWriteris closed.- Parameters:
message- Description of the error
-
throwExceptionAndClose
In case of any exceptions, aTextWritingExceptionis thrown, and the outputWriteris closed.- Parameters:
message- Description of the errorcause- the exception to be wrapped by aTextWritingException
-
throwExceptionAndClose
private TextWritingException throwExceptionAndClose(String message, String recordCharacters, Throwable cause) In case of any exceptions, aTextWritingExceptionis thrown, and the outputWriteris closed.- Parameters:
message- Description of the errorrecordCharacters- characters used to write to the output at the time the exception happenedcause- the exception to be wrapped by aTextWritingException
-
throwExceptionAndClose
private TextWritingException throwExceptionAndClose(String message, Object[] recordValues, Throwable cause) In case of any exceptions, aTextWritingExceptionis thrown, and the outputWriteris closed.- Parameters:
message- Description of the errorrecordValues- values used to write to the output at the time the exception happenedcause- the exception to be wrapped by aTextWritingException
-
getStringValue
Converts a given object to its String representation for writing to aString- If the object is null, then
nullValueis returned. - If the String representation of this object is an empty String, then
emptyValueis returned
- Parameters:
element- the object to be converted into a String.- Returns:
- the String representation of the given object
- If the object is null, then
-
addValues
Writes a sequence of values to a row in memory. Subsequent calls to this method will add the given values in a new column of the same row, untilwriteValuesToRow()is called to flush all values accumulated and effectively write a new record to the output- Parameters:
values- the values to be written
-
addStringValues
Writes a sequence of Strings to a row in memory. Subsequent calls to this method will add the given values in a new column of the same row, untilwriteValuesToRow()is called to flush all values accumulated and effectively write a new record to the output- Parameters:
values- the values to be written
-
addValues
Writes a sequence of values to a row in memory. Subsequent calls to this method will add the given values in a new column of the same row, untilwriteValuesToRow()is called to flush all values accumulated and effectively write a new record to the output- Parameters:
values- the values to be written
-
addValue
Writes a value to a row in memory. Subsequent calls to this method will add the given values in a new column of the same row, untilwriteValuesToRow()is called to flush all values accumulated and effectively write a new record to the output- Parameters:
value- the value to be written
-
fillPartialLineToMatchHeaders
private void fillPartialLineToMatchHeaders() -
writeValuesToRow
public final void writeValuesToRow()Writes the contents accumulated in an internal in-memory row (usingor #writeValue()to a new record in the output. -
addValue
Writes a value to a row in memory. Subsequent calls to this method will add the given values in a new column of the same row, untilwriteValuesToRow()is called to flush all values accumulated and effectively write a new record to the output- Parameters:
index- the position in the row that should receive the value.value- the value to be written
-
addValue
Writes a value to a row in memory. Subsequent calls to this method will add the given values in a new column of the same row, untilwriteValuesToRow()is called to flush all values accumulated and effectively write a new record to the output- Parameters:
headerName- the name of the column of the new row that should receive the value.value- the value to be written
-
addValue
private final void addValue(NormalizedString[] headersInContext, NormalizedString headerName, boolean ignoreOnMismatch, Object value) -
getFieldIndex
private int getFieldIndex(NormalizedString[] headersInContext, NormalizedString headerName, boolean ignoreOnMismatch) Calculates the index of a header name in relation to the originalheadersarray defined in this writer- Parameters:
headersInContext- headers currently in use (they might change).headerName- the name of the header whose position will be identifiedignoreOnMismatch- flag indicating that if the header is not found, no exception is to be thrown, and -1 should be returned instead.- Returns:
- the position of the given header, or -1 if it's not found when ignoreOnMismatch is set to
true
-
discardValues
public final void discardValues()Discards the contents written to the internal in-memory row (usingor #writeValue(). -
writeHeadersToString
Writes the headers defined inCommonSettings.getHeaders()to aString- Returns:
- a formatted
Stringcontaining the headers defined inCommonSettings.getHeaders()
-
writeHeadersToString
Writes the given collection of headers to aStringATextWritingExceptionwill be thrown if no headers were defined.- Parameters:
headers- the headers to write to aString- Returns:
- a formatted
Stringcontaining the given headers
-
writeHeadersToString
Writes the given collection of headers to aStringATextWritingExceptionwill be thrown if no headers were defined or if records were already written to aString- Parameters:
headers- the headers to write to aString- Returns:
- a formatted
Stringcontaining the given headers
-
processRecordsToString
Iterates over all records, processes each one with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), and writes them to aListofString. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Parameters:
records- the records to be transformed by aRowWriterProcessorand then written to aListofString.- Returns:
- a
Listcontaining the information transformed from the given records as formattedStrings
-
processRecordsToString
Iterates over all records, processes each one with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), and writes them them to aListofString. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Parameters:
records- the records to transformed by aRowWriterProcessorand then written aString.- Returns:
- a
Listcontaining the information transformed from the given records as formattedStrings
-
processRecordToString
Processes the data given for an individual record with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes it to aString. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Parameters:
record- the information of a single record to be transformed by aRowWriterProcessorand then written to aString.- Returns:
- a formatted
Stringcontaining the information transformed from the given record
-
processRecordToString
Processes the data given for an individual record with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes it to aString. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
T- the concrete Record type- Parameters:
record- the information of a single record to be transformed by aRowWriterProcessorand then written to aString.- Returns:
- a formatted
Stringcontaining the information transformed from the given record
-
processRecordToString
Processes the data given for an individual record with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes it. The output will remain open for further writing. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Parameters:
record- the information of a single record to be transformed by aRowWriterProcessorand then written to aString.- Returns:
- a formatted
Stringcontaining the information transformed from the given record
-
writeRowsToString
Iterates over all records and writes them to aListofString. Note this method will not use theRowWriterProcessor. UseprocessRecords(Object[])for that.- Parameters:
rows- the rows to be written to aListofString.- Returns:
- a
Listcontaining the given rows as formattedStrings
-
writeRowsToString
Iterates over all records and writes them to aListofString. Note this method will not use theRowWriterProcessor. UseprocessRecords(Iterable)for that.- Type Parameters:
C- Collection of objects containing values of a row- Parameters:
rows- the rows to be written to aListofString.- Returns:
- a
Listcontaining the given rows as formattedStrings
-
writeStringRowsToString
Iterates over all records and writes them to aListofString. Note this method will not use theRowWriterProcessor. UseprocessRecords(Iterable)for that.- Type Parameters:
C- Collection of objects containing values of a row- Parameters:
rows- the rows to be written to aListofString.- Returns:
- a
Listcontaining the given rows as formattedStrings
-
writeRowsToString
Iterates over all records and writes them to aListofString. Note this method will not use theRowWriterProcessor. UseprocessRecords(Iterable)for that.- Parameters:
rows- the rows to be written to aListofString.- Returns:
- a
Listcontaining the given rows as formattedStrings
-
writeStringRowsToString
Iterates over all records and writes them to aListofString. Note this method will not use theRowWriterProcessor. UseprocessRecords(Iterable)for that.- Parameters:
rows- the rows to be written to aListofString.- Returns:
- a
Listcontaining the given rows as formattedStrings
-
writeRecordsToString
Iterates over all records and writes them to aListofString. Note this method will not use theRowWriterProcessor. UseprocessRecords(Iterable)for that.- Parameters:
rows- the rows to be written to aListofString.- Returns:
- a
Listcontaining the given rows as formattedStrings
-
writeRowToString
Writes the data given for an individual record to aString. Note this method will not use theRowWriterProcessor. UseprocessRecord(Object)for that.- Parameters:
row- the information of a single record to be written to aString- Returns:
- a formatted
Stringcontaining the information of the given record
-
writeRowToString
Writes the data given for an individual record to aString. If the given data is null or empty, andCommonSettings.getSkipEmptyLines()is true,nullwill be returned In case of any errors, aTextWritingExceptionwill be thrown. Note this method will not use theRowWriterProcessor. UseprocessRecord(Object)for that.- Parameters:
row- the information of a single record to be written to aString.- Returns:
- a formatted
Stringcontaining the information of the given record
-
writeRecordToString
Writes the data given for an individual record to aString. If the given data is null or empty, andCommonSettings.getSkipEmptyLines()is true,nullwill be returned In case of any errors, aTextWritingExceptionwill be thrown. Note this method will not use theRowWriterProcessor. UseprocessRecord(Object)for that.- Parameters:
row- the information of a single record to be written to aString.- Returns:
- a formatted
Stringcontaining the information of the given record
-
writeRowToString
Writes the data given for an individual record to aString. If the given data is null or empty, andCommonSettings.getSkipEmptyLines()is true,nullwill be returned In case of any errors, aTextWritingExceptionwill be thrown. Note this method will not use theRowWriterProcessor. UseprocessRecord(Object)for that.- Parameters:
row- the information of a single record to be written to aString.- Returns:
- a formatted
Stringcontaining the information of the given record
-
adjustRowLength
-
commentRowToString
Writes a comment row to aString- Parameters:
comment- the contents to be written as a comment to aString.- Returns:
- a formatted
Stringcontaining the comment.
-
internalWriteRowToString
Writes the accumulated value of a record to the output, followed by a newline, and increases the record count. The newline character sequence will conform to what is specified inFormat.getLineSeparator()The contents ofrowAppenderdepend on the concrete implementation ofprocessRow(Object[])- Returns:
- a formatted
Stringcontaining the comment.
-
writeValuesToString
Writes the contents accumulated in an internal in-memory row (usingor #addValue()as aString- Returns:
- a formatted
Stringcontaining the information accumulated in the internal in-memory row.
-
processValuesToRow
public final void processValuesToRow()Writes the contents accumulated in an internal in-memory row (usingor #addValue()to a new record in the output. The objects added to this row will be processed with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(). The output will remain open for further writing. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor(). -
processValuesToString
Writes the contents accumulated in an internal in-memory row (usingor #addValue()to aStringThe objects added to this row will be processed with theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(). The output will remain open for further writing. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Returns:
- a formatted
Stringcontaining the result produced by theRowWriterProcessorusing the values accumulated in internal in-memory row.
-
getRecordCount
public final long getRecordCount()Returns the number of records written to the output so far- Returns:
- the number of records written to the output so far
-
writeValuesFromMap
Writes values from an implementation ofMapto a partial output record, ready to be written to the output. Values will be stored under a column identified by the headers. If no headers are defined, the keys of the map will be used to initialize an internal header row. A map of headers can be optionally provided to assign a name to the keys of the input map. This is useful when the input map has keys will generate unwanted header names.- Type Parameters:
K- type of the key in both rowData and headerMapping maps.- Parameters:
headerMapping- an optional map associating keys of the rowData map with expected header namesrowData- the data to be written. Its keys will be used to form a header row in case no headers are available.
-
setHeadersFromMap
Iterates over the keys of a map and builds an internal header row.- Parameters:
map- the input map whose keys will be used to generate headers for the output.keys- indicates whether to take the map keys or values to build the header rows.
-
writeRowToString
Writes the values of a given map to aStringformatted to according to the specified output format. Note this method will not use theRowWriterProcessor.- Parameters:
rowData- the map whose values will be used to generate aString.- Returns:
- a
Stringcontaining the given data as a formattedString
-
writeRow
Writes the values of a given map into new output record Note this method will not use theRowWriterProcessor.- Parameters:
rowData- the map whose values will be used to generate a new record
-
writeRowToString
Writes the values of a given map to aStringformatted to according to the specified output format. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate aString.- Returns:
- a
Stringcontaining the given data as a formattedString
-
writeRow
Writes the values of a given map into new output record Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate a new record
-
writeRowsToString
Writes the values of a given map to aListofStringformatted to according to the specified output format. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key typeI- the iterable type- Parameters:
rowData- the map whose values will be used to generate aListofString.- Returns:
- a
Listof formattedString, eachStringrepresenting one successful iteration over at least one element of the iterators in the map.
-
writeRows
Writes the values of a given map to multiple output records Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key typeI- the iterable type- Parameters:
rowData- the map whose values will be used to generate a number of output records
-
writeRowsToString
public final <K,I extends Iterable<?>> List<String> writeRowsToString(Map<K, String> headerMapping, Map<K, I> rowData) Writes the values of a given map to aListofStringformatted to according to the specified output format. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key typeI- the iterable type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate aListofString.- Returns:
- a
Listof formattedString, eachStringrepresenting one successful iteration over at least one element of the iterators in the map.
-
writeRows
public final <K,I extends Iterable<?>> void writeRows(Map<K, String> headerMapping, Map<K, I> rowData) Writes the values of a given map to multiple output records Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key typeI- the iterable type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate a number of output records
-
writeRows
private <K,I extends Iterable<?>> void writeRows(Map<K, String> headerMapping, Map<K, I> rowData, List<String> outputList, boolean useRowProcessor) Writes the values of a given map to aListofStringformatted to according to the specified output format. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key typeI- the iterable type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate aListofString.outputList- an outputListto fill with formattedStrings, eachStringrepresenting one successful iteration over at least one element of the iterators in the map.
-
writeStringRowsToString
public final <K> List<String> writeStringRowsToString(Map<K, String> headerMapping, Map<K, String[]> rowData) Writes the values of a given map to aListofStringformatted to according to the specified output format. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate aListofString.- Returns:
- a
Listof formattedString, eachStringrepresenting one successful iteration over at least one element of the iterators in the map.
-
writeRecordsToString
public final <K> List<String> writeRecordsToString(Map<K, String> headerMapping, Map<K, ? extends Record> rowData) Writes the values of a given map to aListofStringformatted to according to the specified output format. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate aListofString.- Returns:
- a
Listof formattedString, eachStringrepresenting one successful iteration over at least one element of the iterators in the map.
-
writeStringRows
Writes the values of a given map to multiple output records Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate a number of output records
-
writeRecords
Writes the values of a given map to multiple output records Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate a number of output records
-
writeObjectRowsToString
public final <K> List<String> writeObjectRowsToString(Map<K, String> headerMapping, Map<K, Object[]> rowData) Writes the values of a given map to aListofStringformatted to according to the specified output format. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate aListofString.- Returns:
- a
Listof formattedString, eachStringrepresenting one successful iteration over at least one element of the iterators in the map.
-
writeObjectRows
Writes the values of a given map to multiple output records Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate a number of output records
-
wrapObjectArray
-
wrapStringArray
-
wrapRecordValues
-
writeObjectRowsAndClose
Writes the values of a given map to multiple output records and closes the output when finished. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate a number of output records
-
writeStringRowsAndClose
Writes the values of a given map to multiple output records and closes the output when finished. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate a number of output records
-
writeRecordsAndClose
public final <K> void writeRecordsAndClose(Map<K, String> headerMapping, Map<K, ? extends Record> rowData) Writes the values of a given map to multiple output records and closes the output when finished. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate a number of output records
-
writeObjectRowsAndClose
Writes the values of a given map to multiple output records and closes the output when finished. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key type- Parameters:
rowData- the map whose values will be used to generate a number of output records
-
writeStringRowsAndClose
Writes the values of a given map to multiple output records and closes the output when finished. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key type- Parameters:
rowData- the map whose values will be used to generate a number of output records
-
writeRecordsAndClose
Writes the values of a given map to multiple output records and closes the output when finished. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key type- Parameters:
rowData- the map whose values will be used to generate a number of output records
-
writeRowsAndClose
public final <K,I extends Iterable<?>> void writeRowsAndClose(Map<K, String> headerMapping, Map<K, I> rowData) Writes the values of a given map to multiple output records and closes the output when finished. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key typeI- the iterable type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate a number of output records
-
writeRowsAndClose
Writes the values of a given map to multiple output records and closes the output when finished. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. Note this method will not use theRowWriterProcessor.- Type Parameters:
K- the key typeI- the iterable type- Parameters:
rowData- the map whose values will be used to generate a number of output records
-
processRecordToString
Processes the values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result intoStringformatted according to the specified output format. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Parameters:
rowData- the map whose values will be used to generate aListofString.- Returns:
- a
Stringcontaining the given data as a formattedString
-
processRecord
Processes the values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result into a new output record ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Parameters:
rowData- the map whose values will be used to generate aListofString.
-
processRecordToString
Processes the values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result intoStringformatted according to the specified output format. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate aListofString.- Returns:
- a
Stringcontaining the given data as a formattedString
-
processRecord
Processes the values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result into a new output record ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate aListofString.
-
processRecordsToString
Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result into aListofStringformatted to according to the specified output format. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
K- the key typeI- the iterable type- Parameters:
rowData- the map whose values will be used to generate aListofString.- Returns:
- a
Listof formattedString, eachStringrepresenting one successful iteration over at least one element of the iterators in the map.
-
processRecords
Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes all values to the output . The output will remain open for further write operations. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
K- the key typeI- the iterable type- Parameters:
rowData- the map whose values will be used to generate a number of output records
-
processRecordsToString
public final <K,I extends Iterable<?>> List<String> processRecordsToString(Map<K, String> headerMapping, Map<K, I> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result into aListofStringformatted to according to the specified output format. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
K- the key typeI- the iterable type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate aListofString.- Returns:
- a
Listof formattedString, eachStringrepresenting one successful iteration over at least one element of the iterators in the map.
-
processRecords
public final <K,I extends Iterable<?>> void processRecords(Map<K, String> headerMapping, Map<K, I> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes all values to the output . The output will remain open for further write operations. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
K- the key typeI- the iterable type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate a number of output records
-
processObjectRecordsToString
Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result into aListofStringformatted to according to the specified output format. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
K- the key type- Parameters:
rowData- the map whose values will be used to generate aListofString.- Returns:
- a
Listof formattedString, eachStringrepresenting one successful iteration over at least one element of the iterators in the map.
-
processObjectRecordsToString
public final <K> List<String> processObjectRecordsToString(Map<K, String> headerMapping, Map<K, Object[]> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor()and writes the result into aListofStringformatted to according to the specified output format. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate aListofString.- Returns:
- a
Listof formattedString, eachStringrepresenting one successful iteration over at least one element of the iterators in the map.
-
processObjectRecords
Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes all values to the output . The output will remain open for further write operations. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate a number of output records
-
processObjectRecordsAndClose
public final <K> void processObjectRecordsAndClose(Map<K, String> headerMapping, Map<K, Object[]> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes all values to the output and closes the writer. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
K- the key type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate a number of output records
-
processObjectRecordsAndClose
Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes all values to the output and closes the writer. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
K- the key type- Parameters:
rowData- the map whose values will be used to generate a number of output records
-
processRecordsAndClose
public final <K,I extends Iterable<?>> void processRecordsAndClose(Map<K, String> headerMapping, Map<K, I> rowData) Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes all values to the output and closes the writer. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
K- the key typeI- the iterable type- Parameters:
headerMapping- a mapping associating the keys of the input map to their corresponding header names.rowData- the map whose values will be used to generate a number of output records
-
processRecordsAndClose
Processes the data in all values of a map using theRowWriterProcessorprovided byCommonWriterSettings.getRowWriterProcessor(), then writes all values to the output and closes the writer. Each value is expected to be iterable and the result of this method will produce the number of records equal to the longest iterable. A new record will be created each time at least oneIterator.hasNext()returnstrue.Nullwill be written when a iterator has been fully read. ATextWritingExceptionwill be thrown if noRowWriterProcessoris provided byCommonWriterSettings.getRowWriterProcessor().- Type Parameters:
K- the key typeI- the iterable type- Parameters:
rowData- the map whose values will be used to generate a number of output records
-
getContent
-
getContent
-
allowTrim
protected final boolean allowTrim(int fieldIndex) Checks whether the writer can remove trailing/leading whitespaces from a value being written. Applies to headers where names can be conflicting if trimmed for example' a 'and'a'will become the same value if the spaces are removed)- Parameters:
fieldIndex- index of the field to be written.- Returns:
trueif the value being written is not a header name, or it is a header name that won't conflict with another header if its surrounding whitespaces are trimmed.
-