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
public abstract class AbstractWriter<S extends CommonWriterSettings<?>> extends java.lang.Object
The AbstractWriter class provides a common ground for all writers in univocity-parsers. It handles all settings defined byCommonWriterSettings
, and delegates the writing algorithm implementation to its subclasses through the abstract methodprocessRow(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
-
-
Field Summary
Fields Modifier and Type Field Description protected WriterCharAppender
appender
private boolean
columnReorderingEnabled
protected char
comment
private NormalizedString[]
dummyHeaderRow
protected java.lang.String
emptyValue
private boolean
enableNewlineAfterRecord
private int
errorContentLength
protected boolean
expandRows
private java.util.Map<NormalizedString[],java.util.Map<NormalizedString,java.lang.Integer>>
headerIndexes
protected NormalizedString[]
headers
protected boolean[]
headerTrimFlags
protected boolean
ignoreLeading
protected boolean
ignoreTrailing
private int[]
indexesToWrite
private CommonSettings<DummyFormat>
internalSettings
private boolean
isHeaderWritingEnabled
private int
largestRowLength
private char[]
lineSeparator
protected java.lang.String
nullValue
private java.lang.Object[]
outputRow
private java.lang.Object[]
partialLine
private int
partialLineIndex
protected long
recordCount
private WriterCharAppender
rowAppender
private boolean
skipEmptyLines
protected boolean
usingNullOrEmptyValue
private boolean
usingSwitch
protected int
whitespaceRangeStart
private java.io.Writer
writer
private RowWriterProcessor
writerProcessor
protected boolean
writingHeaders
-
Constructor Summary
Constructors Constructor Description AbstractWriter(java.io.File file, java.lang.String encoding, S settings)
All writers must support, at the very least, the settings provided byCommonWriterSettings
.AbstractWriter(java.io.File file, java.nio.charset.Charset encoding, S settings)
All writers must support, at the very least, the settings provided byCommonWriterSettings
.AbstractWriter(java.io.File file, S settings)
All writers must support, at the very least, the settings provided byCommonWriterSettings
.AbstractWriter(java.io.OutputStream output, java.lang.String encoding, S settings)
All writers must support, at the very least, the settings provided byCommonWriterSettings
.AbstractWriter(java.io.OutputStream output, java.nio.charset.Charset encoding, S settings)
All writers must support, at the very least, the settings provided byCommonWriterSettings
.AbstractWriter(java.io.OutputStream output, S settings)
All writers must support, at the very least, the settings provided byCommonWriterSettings
.AbstractWriter(java.io.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
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addStringValues(java.util.Collection<java.lang.String> values)
Writes a sequence of Strings to a row in memory.void
addValue(int index, java.lang.Object value)
Writes a value to a row in memory.private void
addValue(NormalizedString[] headersInContext, NormalizedString headerName, boolean ignoreOnMismatch, java.lang.Object value)
void
addValue(java.lang.Object value)
Writes a value to a row in memory.void
addValue(java.lang.String headerName, java.lang.Object value)
Writes a value to a row in memory.void
addValues(java.lang.Object... values)
Writes a sequence of values to a row in memory.void
addValues(java.util.Collection<?> values)
Writes a sequence of values to a row in memory.private java.lang.Object[]
adjustRowLength(java.lang.Object[] row)
protected boolean
allowTrim(int fieldIndex)
Checks whether the writer can remove trailing/leading whitespaces from a value being written.protected void
appendToRow(char ch)
Appends the given character to the output row.protected void
appendToRow(char[] chars)
Appends the given character sequence to the output rowprotected void
appendValueToRow()
Appends the processed sequence of characters inappender
to the output row.void
close()
Closes theWriter
given in this class constructor.void
commentRow(java.lang.String comment)
Writes a comment row to the output.java.lang.String
commentRowToString(java.lang.String comment)
Writes a comment row to aString
void
discardValues()
Discards the contents written to the internal in-memory row (usingor #writeValue()
.protected void
enableNewlineAfterRecord(boolean enableNewlineAfterRecord)
protected java.lang.Object[]
expand(java.lang.Object[] row, int length, java.lang.Integer h2)
private <T> void
fillOutputRow(T[] row)
Used when fields were selected and the input rows have a different order than the output.private void
fillPartialLineToMatchHeaders()
void
flush()
Flushes theWriter
given in this class constructor.private java.lang.String
getContent(java.lang.CharSequence tmp)
private java.lang.Object[]
getContent(java.lang.Object[] tmp)
private int
getFieldIndex(NormalizedString[] headersInContext, NormalizedString headerName, boolean ignoreOnMismatch)
Calculates the index of a header name in relation to the originalheaders
array defined in this writerlong
getRecordCount()
Returns the number of records written to the output so farprivate NormalizedString[]
getRowProcessorHeaders()
protected java.lang.String
getStringValue(java.lang.Object element)
Converts a given object to its String representation for writing to aString
If the object is null, thennullValue
is returned. If the String representation of this object is an empty String, thenemptyValue
is returnedprotected abstract void
initialize(S settings)
Initializes the concrete implementation of this class with format-specific settings.private void
internalWriteRow()
Writes the accumulated value of a record to the output, followed by a newline, and increases the record count.private java.lang.String
internalWriteRowToString()
Writes the accumulated value of a record to the output, followed by a newline, and increases the record count.<K> void
processObjectRecords(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.Object[]> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes all values to the output .<K> void
processObjectRecordsAndClose(java.util.Map<K,java.lang.Object[]> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes all values to the output and closes the writer.<K> void
processObjectRecordsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.Object[]> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes all values to the output and closes the writer.<K> java.util.List<java.lang.String>
processObjectRecordsToString(java.util.Map<K,java.lang.Object[]> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result into aList
ofString
formatted to according to the specified output format.<K> java.util.List<java.lang.String>
processObjectRecordsToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.Object[]> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result into aList
ofString
formatted to according to the specified output format.void
processRecord(java.lang.Object record)
Processes the data given for an individual record with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes it.void
processRecord(java.lang.Object... record)
Processes the data given for an individual record with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes it.void
processRecord(java.util.Map<?,?> rowData)
Processes the values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result into a new output record ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.<K> void
processRecord(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
Processes the values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result into a new output record ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.<T extends Record>
voidprocessRecord(T record)
void
processRecords(java.lang.Iterable<?> records)
Iterates over all records, processes each one with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, and writes them.void
processRecords(java.lang.Object[] records)
Iterates over all records, processes each one with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, and writes them.<K,I extends java.lang.Iterable<?>>
voidprocessRecords(java.util.Map<K,I> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes all values to the output .<K,I extends java.lang.Iterable<?>>
voidprocessRecords(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes all values to the output .<T extends Record>
voidprocessRecords(T[] records)
Iterates over all records, processes each one with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, and writes them.void
processRecordsAndClose(java.lang.Iterable<?> allRecords)
Iterates over all records, processes each one with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, and writes them, then finally and closes the output ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.void
processRecordsAndClose(java.lang.Object[] allRecords)
Iterates over all records, processes each one with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, and writes them, then finally and closes the output ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.<K,I extends java.lang.Iterable<?>>
voidprocessRecordsAndClose(java.util.Map<K,I> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes all values to the output and closes the writer.<K,I extends java.lang.Iterable<?>>
voidprocessRecordsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes all values to the output and closes the writer.java.util.List<java.lang.String>
processRecordsToString(java.lang.Iterable<?> records)
Iterates over all records, processes each one with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, and writes them to aList
ofString
.java.util.List<java.lang.String>
processRecordsToString(java.lang.Object[] records)
Iterates over all records, processes each one with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, and writes them them to aList
ofString
.<K,I extends java.lang.Iterable<?>>
java.util.List<java.lang.String>processRecordsToString(java.util.Map<K,I> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result into aList
ofString
formatted to according to the specified output format.<K,I extends java.lang.Iterable<?>>
java.util.List<java.lang.String>processRecordsToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result into aList
ofString
formatted to according to the specified output format.java.lang.String
processRecordToString(java.lang.Object record)
Processes the data given for an individual record with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes it.java.lang.String
processRecordToString(java.lang.Object... record)
Processes the data given for an individual record with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes it to aString
.java.lang.String
processRecordToString(java.util.Map<?,?> rowData)
Processes the values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result intoString
formatted according to the specified output format.<K> java.lang.String
processRecordToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
Processes the values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result intoString
formatted according to the specified output format.<T extends Record>
java.lang.StringprocessRecordToString(T record)
Processes the data given for an individual record with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes it to aString
.protected abstract void
processRow(java.lang.Object[] row)
Format-specific implementation for writing a single record into the output.void
processValuesToRow()
Writes the contents accumulated in an internal in-memory row (usingor #addValue()
to a new record in the output.java.lang.String
processValuesToString()
Writes the contents accumulated in an internal in-memory row (usingor #addValue()
to aString
The objects added to this row will be processed with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
.private void
setHeadersFromMap(java.util.Map<?,?> map, boolean keys)
Iterates over the keys of a map and builds an internal header row.protected static int
skipLeadingWhitespace(int whitespaceRangeStart, java.lang.String element)
Identifies the starting character index of a value being written if leading whitespaces are to be discarded.private void
submitRow(java.lang.Object[] row)
Submits a row for processing by the format-specific implementation.private TextWritingException
throwExceptionAndClose(java.lang.String message)
In case of any exceptions, aTextWritingException
is thrown, and the outputWriter
is closed.private TextWritingException
throwExceptionAndClose(java.lang.String message, java.lang.Object[] recordValues, java.lang.Throwable cause)
In case of any exceptions, aTextWritingException
is thrown, and the outputWriter
is closed.private TextWritingException
throwExceptionAndClose(java.lang.String message, java.lang.String recordCharacters, java.lang.Throwable cause)
In case of any exceptions, aTextWritingException
is thrown, and the outputWriter
is closed.private TextWritingException
throwExceptionAndClose(java.lang.String message, java.lang.Throwable cause)
In case of any exceptions, aTextWritingException
is thrown, and the outputWriter
is closed.void
updateFieldExclusion(java.lang.Integer... fieldIndexesToExclude)
Updates the selection of fields to exclude when writing.void
updateFieldExclusion(java.lang.String... fieldsToExclude)
Updates the selection of fields to exclude when writing.void
updateFieldSelection(java.lang.Integer... newFieldSelectionByIndex)
Updates the selection of fields to write.void
updateFieldSelection(java.lang.String... newFieldSelection)
Updates the selection of fields to write.private void
updateIndexesToWrite(CommonSettings<?> settings)
Update indexes to write based on the field selection provided by the user.private <K> java.util.Map<K,java.lang.Iterable<java.lang.Object>>
wrapObjectArray(java.util.Map<K,java.lang.Object[]> rowData)
private <K> java.util.Map<K,java.lang.Iterable<java.lang.String>>
wrapRecordValues(java.util.Map<K,? extends Record> rowData)
private <K> java.util.Map<K,java.lang.Iterable<java.lang.String>>
wrapStringArray(java.util.Map<K,java.lang.String[]> rowData)
void
writeEmptyRow()
Writes an empty line to the output, unless this is aFixedWidthWriter
whoseFixedWidthWriterSettings.getWriteLineSeparatorAfterRecord()
evaluates tofalse
.void
writeHeaders()
Writes the headers defined inCommonSettings.getHeaders()
ATextWritingException
will be thrown if no headers were defined or if records were already written to the output.void
writeHeaders(java.lang.String... headers)
Writes the given collection of headers to the output.void
writeHeaders(java.util.Collection<?> headers)
Writes the given collection of headers to the output.java.lang.String
writeHeadersToString()
Writes the headers defined inCommonSettings.getHeaders()
to aString
java.lang.String
writeHeadersToString(java.lang.String... headers)
Writes the given collection of headers to aString
ATextWritingException
will be thrown if no headers were defined or if records were already written to aString
java.lang.String
writeHeadersToString(java.util.Collection<?> headers)
Writes the given collection of headers to aString
ATextWritingException
will be thrown if no headers were defined.<K> void
writeObjectRows(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.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.<K> void
writeObjectRowsAndClose(java.util.Map<K,java.lang.Object[]> rowData)
Writes the values of a given map to multiple output records and closes the output when finished.<K> void
writeObjectRowsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.Object[]> rowData)
Writes the values of a given map to multiple output records and closes the output when finished.<K> java.util.List<java.lang.String>
writeObjectRowsToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.Object[]> rowData)
Writes the values of a given map to aList
ofString
formatted to according to the specified output format.<T extends Record>
voidwriteRecord(T row)
Writes the data given for an individual record.void
writeRecords(java.util.Collection<? extends Record> rows)
Iterates over all records and writes them to the output.<K> void
writeRecords(java.util.Map<K,java.lang.String> headerMapping, java.util.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.void
writeRecordsAndClose(java.util.Collection<? extends Record> allRows)
Iterates over all records, writes them and closes the output.<K> void
writeRecordsAndClose(java.util.Map<K,? extends Record> rowData)
Writes the values of a given map to multiple output records and closes the output when finished.<K> void
writeRecordsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,? extends Record> rowData)
Writes the values of a given map to multiple output records and closes the output when finished.java.util.List<java.lang.String>
writeRecordsToString(java.util.Collection<? extends Record> rows)
Iterates over all records and writes them to aList
ofString
.<K> java.util.List<java.lang.String>
writeRecordsToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,? extends Record> rowData)
Writes the values of a given map to aList
ofString
formatted to according to the specified output format.<T extends Record>
java.lang.StringwriteRecordToString(T row)
Writes the data given for an individual record to aString
.void
writeRow(java.lang.Object... row)
Writes the data given for an individual record.void
writeRow(java.lang.String row)
Writes a plain (potentially free-text) String as a line to the output.void
writeRow(java.lang.String[] row)
Writes the data given for an individual record.void
writeRow(java.util.Collection<?> row)
Writes the data given for an individual record.void
writeRow(java.util.Map<?,?> rowData)
Writes the values of a given map into new output record Note this method will not use theRowWriterProcessor
.<K> void
writeRow(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
Writes the values of a given map into new output record Note this method will not use theRowWriterProcessor
.<C extends java.util.Collection<?>>
voidwriteRows(java.lang.Iterable<C> rows)
Iterates over all records and writes them to the output.void
writeRows(java.lang.Object[][] rows)
Iterates over all records and writes them to the output.void
writeRows(java.util.Collection<java.lang.Object[]> rows)
Iterates over all records and writes them to the output.<K,I extends java.lang.Iterable<?>>
voidwriteRows(java.util.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.<K,I extends java.lang.Iterable<?>>
voidwriteRows(java.util.Map<K,java.lang.String> headerMapping, java.util.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.private <K,I extends java.lang.Iterable<?>>
voidwriteRows(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData, java.util.List<java.lang.String> outputList, boolean useRowProcessor)
Writes the values of a given map to aList
ofString
formatted to according to the specified output format.<C extends java.util.Collection<?>>
voidwriteRowsAndClose(java.lang.Iterable<C> allRows)
Iterates over all records, writes them and closes the output.void
writeRowsAndClose(java.lang.Object[][] allRows)
Iterates over all records, writes them and closes the output.void
writeRowsAndClose(java.util.Collection<java.lang.Object[]> allRows)
Iterates over all records, writes them and closes the output.<K,I extends java.lang.Iterable<?>>
voidwriteRowsAndClose(java.util.Map<K,I> rowData)
Writes the values of a given map to multiple output records and closes the output when finished.<K,I extends java.lang.Iterable<?>>
voidwriteRowsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData)
Writes the values of a given map to multiple output records and closes the output when finished.<C extends java.util.Collection<?>>
java.util.List<java.lang.String>writeRowsToString(java.lang.Iterable<C> rows)
Iterates over all records and writes them to aList
ofString
.java.util.List<java.lang.String>
writeRowsToString(java.lang.Object[][] rows)
Iterates over all records and writes them to aList
ofString
.java.util.List<java.lang.String>
writeRowsToString(java.util.Collection<java.lang.Object[]> rows)
Iterates over all records and writes them to aList
ofString
.<K,I extends java.lang.Iterable<?>>
java.util.List<java.lang.String>writeRowsToString(java.util.Map<K,I> rowData)
Writes the values of a given map to aList
ofString
formatted to according to the specified output format.<K,I extends java.lang.Iterable<?>>
java.util.List<java.lang.String>writeRowsToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData)
Writes the values of a given map to aList
ofString
formatted to according to the specified output format.java.lang.String
writeRowToString(java.lang.Object... row)
Writes the data given for an individual record to aString
.java.lang.String
writeRowToString(java.lang.String[] row)
Writes the data given for an individual record to aString
.java.lang.String
writeRowToString(java.util.Collection<?> row)
Writes the data given for an individual record to aString
.java.lang.String
writeRowToString(java.util.Map<?,?> rowData)
Writes the values of a given map to aString
formatted to according to the specified output format.<K> java.lang.String
writeRowToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
Writes the values of a given map to aString
formatted to according to the specified output format.<C extends java.util.Collection<?>>
voidwriteStringRows(java.lang.Iterable<C> rows)
Iterates over all records and writes them to the output.void
writeStringRows(java.util.Collection<java.lang.String[]> rows)
Iterates over all records and writes them to the output.<K> void
writeStringRows(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.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.void
writeStringRowsAndClose(java.util.Collection<java.lang.String[]> allRows)
Iterates over all records, writes them and closes the output.<K> void
writeStringRowsAndClose(java.util.Map<K,java.lang.String[]> rowData)
Writes the values of a given map to multiple output records and closes the output when finished.<K> void
writeStringRowsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.String[]> rowData)
Writes the values of a given map to multiple output records and closes the output when finished.<C extends java.util.Collection<?>>
java.util.List<java.lang.String>writeStringRowsToString(java.lang.Iterable<C> rows)
Iterates over all records and writes them to aList
ofString
.java.util.List<java.lang.String>
writeStringRowsToString(java.util.Collection<java.lang.String[]> rows)
Iterates over all records and writes them to aList
ofString
.<K> java.util.List<java.lang.String>
writeStringRowsToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.String[]> rowData)
Writes the values of a given map to aList
ofString
formatted to according to the specified output format.private <K> void
writeValuesFromMap(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
Writes values from an implementation ofMap
to a partial output record, ready to be written to the output.void
writeValuesToRow()
Writes the contents accumulated in an internal in-memory row (usingor #writeValue()
to a new record in the output.java.lang.String
writeValuesToString()
Writes the contents accumulated in an internal in-memory row (usingor #addValue()
as aString
-
-
-
Field Detail
-
writerProcessor
private final RowWriterProcessor writerProcessor
-
writer
private java.io.Writer writer
-
skipEmptyLines
private final boolean skipEmptyLines
-
comment
protected final char comment
-
rowAppender
private final WriterCharAppender rowAppender
-
isHeaderWritingEnabled
private final boolean isHeaderWritingEnabled
-
outputRow
private java.lang.Object[] outputRow
-
indexesToWrite
private int[] indexesToWrite
-
lineSeparator
private final char[] lineSeparator
-
headers
protected NormalizedString[] headers
-
recordCount
protected long recordCount
-
nullValue
protected final java.lang.String nullValue
-
emptyValue
protected final java.lang.String emptyValue
-
appender
protected final WriterCharAppender appender
-
partialLine
private final java.lang.Object[] partialLine
-
partialLineIndex
private int partialLineIndex
-
headerIndexes
private java.util.Map<NormalizedString[],java.util.Map<NormalizedString,java.lang.Integer>> headerIndexes
-
largestRowLength
private int largestRowLength
-
writingHeaders
protected boolean writingHeaders
-
headerTrimFlags
protected boolean[] headerTrimFlags
-
dummyHeaderRow
private NormalizedString[] 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
private final CommonSettings<DummyFormat> internalSettings
-
errorContentLength
private final int errorContentLength
-
-
Constructor Detail
-
AbstractWriter
public AbstractWriter(S settings)
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 ofWriter
to this constructor, only the operations that write to Strings are available.- Parameters:
settings
- the writer configuration
-
AbstractWriter
public AbstractWriter(java.io.File file, S settings)
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
public AbstractWriter(java.io.File file, java.lang.String encoding, S settings)
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
public AbstractWriter(java.io.File file, java.nio.charset.Charset encoding, S settings)
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
public AbstractWriter(java.io.OutputStream output, S settings)
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
public AbstractWriter(java.io.OutputStream output, java.lang.String encoding, S settings)
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
public AbstractWriter(java.io.OutputStream output, java.nio.charset.Charset encoding, S settings)
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
public AbstractWriter(java.io.Writer writer, S settings)
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 Detail
-
enableNewlineAfterRecord
protected void enableNewlineAfterRecord(boolean enableNewlineAfterRecord)
-
initialize
protected abstract void initialize(S settings)
Initializes the concrete implementation of this class with format-specific settings.- Parameters:
settings
- the settings object specific to the format being written.
-
updateIndexesToWrite
private void updateIndexesToWrite(CommonSettings<?> settings)
Update indexes to write based on the field selection provided by the user.
-
updateFieldSelection
public void updateFieldSelection(java.lang.String... newFieldSelection)
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
public void updateFieldSelection(java.lang.Integer... newFieldSelectionByIndex)
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
public void updateFieldExclusion(java.lang.String... fieldsToExclude)
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
public void updateFieldExclusion(java.lang.Integer... fieldIndexesToExclude)
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
private void submitRow(java.lang.Object[] row)
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
protected abstract void processRow(java.lang.Object[] row)
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
appender
object. The an individual value is processed, theappendValueToRow()
method must be called. This will clear the accumulated value inappender
and 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 aFixedWidthWriter
whoseFixedWidthWriterSettings.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 exceptionTextWritingException
will 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:
CharAppender
,CommonWriterSettings
-
appendValueToRow
protected final void appendValueToRow()
Appends the processed sequence of characters inappender
to 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()
ATextWritingException
will be thrown if no headers were defined or if records were already written to the output.
-
writeHeaders
public final void writeHeaders(java.util.Collection<?> headers)
Writes the given collection of headers to the output. ATextWritingException
will 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
public final void writeHeaders(java.lang.String... headers)
Writes the given collection of headers to the output. ATextWritingException
will 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
public final void processRecordsAndClose(java.lang.Iterable<?> allRecords)
Iterates over all records, processes each one with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, and writes them, then finally and closes the output ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Parameters:
allRecords
- the records to be transformed by aRowWriterProcessor
and then written to the output
-
processRecordsAndClose
public final void processRecordsAndClose(java.lang.Object[] allRecords)
Iterates over all records, processes each one with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, and writes them, then finally and closes the output ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Parameters:
allRecords
- the records to be transformed by aRowWriterProcessor
and then written to the output
-
processRecords
public final void processRecords(java.lang.Iterable<?> records)
Iterates over all records, processes each one with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, and writes them. The output will remain open for further writing. ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Parameters:
records
- the records to be transformed by aRowWriterProcessor
and then written to the output
-
processRecords
public final void processRecords(java.lang.Object[] records)
Iterates over all records, processes each one with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, and writes them. The output will remain open for further writing. * ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Parameters:
records
- the records to transformed by aRowWriterProcessor
and then written to the output
-
processRecords
public final <T extends Record> void processRecords(T[] records)
Iterates over all records, processes each one with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, and writes them. The output will remain open for further writing. * ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Type Parameters:
T
- the concrete Record type- Parameters:
records
- the records to transformed by aRowWriterProcessor
and then written to the output
-
processRecord
public final void processRecord(java.lang.Object... record)
Processes the data given for an individual record with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes it. The output will remain open for further writing. ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Parameters:
record
- the information of a single record to be transformed by aRowWriterProcessor
and then written to the output
-
processRecord
public final <T extends Record> void processRecord(T record)
-
processRecord
public final void processRecord(java.lang.Object record)
Processes the data given for an individual record with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes it. The output will remain open for further writing. ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Parameters:
record
- the information of a single record to be transformed by aRowWriterProcessor
and then written to the output
-
getRowProcessorHeaders
private NormalizedString[] getRowProcessorHeaders()
-
writeRowsAndClose
public final <C extends java.util.Collection<?>> void writeRowsAndClose(java.lang.Iterable<C> allRows)
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
public final void writeRowsAndClose(java.util.Collection<java.lang.Object[]> allRows)
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
public final void writeStringRowsAndClose(java.util.Collection<java.lang.String[]> allRows)
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
public final void writeRecordsAndClose(java.util.Collection<? extends Record> allRows)
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
public final void writeRowsAndClose(java.lang.Object[][] allRows)
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
public final void writeRows(java.lang.Object[][] rows)
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
public final <C extends java.util.Collection<?>> void writeRows(java.lang.Iterable<C> rows)
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
public final void writeStringRows(java.util.Collection<java.lang.String[]> rows)
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
public final void writeRecords(java.util.Collection<? extends Record> rows)
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
public final <C extends java.util.Collection<?>> void writeStringRows(java.lang.Iterable<C> rows)
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
public final void writeRows(java.util.Collection<java.lang.Object[]> rows)
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
public final void writeRow(java.util.Collection<?> row)
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
public final void writeRow(java.lang.String[] row)
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, aTextWritingException
will be thrown and theWriter
given 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
public final <T extends Record> void writeRecord(T row)
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, aTextWritingException
will be thrown and theWriter
given 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
public final void writeRow(java.lang.Object... row)
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, aTextWritingException
will be thrown and theWriter
given 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
protected java.lang.Object[] expand(java.lang.Object[] row, int length, java.lang.Integer h2)
-
writeRow
public final void writeRow(java.lang.String row)
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 aFixedWidthWriter
whoseFixedWidthWriterSettings.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 aFixedWidthWriter
whoseFixedWidthWriterSettings.getWriteLineSeparatorAfterRecord()
evaluates tofalse
. The newline character sequence will conform to what is specified inFormat.getLineSeparator()
The output will remain open for further writing.
-
commentRow
public final void commentRow(java.lang.String comment)
Writes a comment row to the output. A newline will automatically written after the given contents, unless this is aFixedWidthWriter
whoseFixedWidthWriterSettings.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 ofrowAppender
depend on the concrete implementation ofprocessRow(Object[])
-
skipLeadingWhitespace
protected static int skipLeadingWhitespace(int whitespaceRangeStart, java.lang.String element)
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 theWriter
given 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 theWriter
given in this class constructor. An IllegalStateException will be thrown in case of any errors.
-
throwExceptionAndClose
private TextWritingException throwExceptionAndClose(java.lang.String message)
In case of any exceptions, aTextWritingException
is thrown, and the outputWriter
is closed.- Parameters:
message
- Description of the error
-
throwExceptionAndClose
private TextWritingException throwExceptionAndClose(java.lang.String message, java.lang.Throwable cause)
In case of any exceptions, aTextWritingException
is thrown, and the outputWriter
is closed.- Parameters:
message
- Description of the errorcause
- the exception to be wrapped by aTextWritingException
-
throwExceptionAndClose
private TextWritingException throwExceptionAndClose(java.lang.String message, java.lang.String recordCharacters, java.lang.Throwable cause)
In case of any exceptions, aTextWritingException
is thrown, and the outputWriter
is 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(java.lang.String message, java.lang.Object[] recordValues, java.lang.Throwable cause)
In case of any exceptions, aTextWritingException
is thrown, and the outputWriter
is 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
protected java.lang.String getStringValue(java.lang.Object element)
Converts a given object to its String representation for writing to aString
- If the object is null, then
nullValue
is returned. - If the String representation of this object is an empty String, then
emptyValue
is 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
public final void addValues(java.lang.Object... values)
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
public final void addStringValues(java.util.Collection<java.lang.String> values)
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
public final void addValues(java.util.Collection<?> values)
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
public final void addValue(java.lang.Object value)
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
public final void addValue(int index, java.lang.Object value)
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
public final void addValue(java.lang.String headerName, java.lang.Object value)
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, java.lang.Object value)
-
getFieldIndex
private int getFieldIndex(NormalizedString[] headersInContext, NormalizedString headerName, boolean ignoreOnMismatch)
Calculates the index of a header name in relation to the originalheaders
array 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
public final java.lang.String writeHeadersToString()
Writes the headers defined inCommonSettings.getHeaders()
to aString
- Returns:
- a formatted
String
containing the headers defined inCommonSettings.getHeaders()
-
writeHeadersToString
public final java.lang.String writeHeadersToString(java.util.Collection<?> headers)
Writes the given collection of headers to aString
ATextWritingException
will be thrown if no headers were defined.- Parameters:
headers
- the headers to write to aString
- Returns:
- a formatted
String
containing the given headers
-
writeHeadersToString
public final java.lang.String writeHeadersToString(java.lang.String... headers)
Writes the given collection of headers to aString
ATextWritingException
will 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
String
containing the given headers
-
processRecordsToString
public final java.util.List<java.lang.String> processRecordsToString(java.lang.Iterable<?> records)
Iterates over all records, processes each one with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, and writes them to aList
ofString
. ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Parameters:
records
- the records to be transformed by aRowWriterProcessor
and then written to aList
ofString
.- Returns:
- a
List
containing the information transformed from the given records as formattedString
s
-
processRecordsToString
public final java.util.List<java.lang.String> processRecordsToString(java.lang.Object[] records)
Iterates over all records, processes each one with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, and writes them them to aList
ofString
. ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Parameters:
records
- the records to transformed by aRowWriterProcessor
and then written aString
.- Returns:
- a
List
containing the information transformed from the given records as formattedString
s
-
processRecordToString
public final java.lang.String processRecordToString(java.lang.Object... record)
Processes the data given for an individual record with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes it to aString
. ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Parameters:
record
- the information of a single record to be transformed by aRowWriterProcessor
and then written to aString
.- Returns:
- a formatted
String
containing the information transformed from the given record
-
processRecordToString
public final <T extends Record> java.lang.String processRecordToString(T record)
Processes the data given for an individual record with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes it to aString
. ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Type Parameters:
T
- the concrete Record type- Parameters:
record
- the information of a single record to be transformed by aRowWriterProcessor
and then written to aString
.- Returns:
- a formatted
String
containing the information transformed from the given record
-
processRecordToString
public final java.lang.String processRecordToString(java.lang.Object record)
Processes the data given for an individual record with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes it. The output will remain open for further writing. ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Parameters:
record
- the information of a single record to be transformed by aRowWriterProcessor
and then written to aString
.- Returns:
- a formatted
String
containing the information transformed from the given record
-
writeRowsToString
public final java.util.List<java.lang.String> writeRowsToString(java.lang.Object[][] rows)
Iterates over all records and writes them to aList
ofString
. Note this method will not use theRowWriterProcessor
. UseprocessRecords(Object[])
for that.- Parameters:
rows
- the rows to be written to aList
ofString
.- Returns:
- a
List
containing the given rows as formattedString
s
-
writeRowsToString
public final <C extends java.util.Collection<?>> java.util.List<java.lang.String> writeRowsToString(java.lang.Iterable<C> rows)
Iterates over all records and writes them to aList
ofString
. 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 aList
ofString
.- Returns:
- a
List
containing the given rows as formattedString
s
-
writeStringRowsToString
public final <C extends java.util.Collection<?>> java.util.List<java.lang.String> writeStringRowsToString(java.lang.Iterable<C> rows)
Iterates over all records and writes them to aList
ofString
. 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 aList
ofString
.- Returns:
- a
List
containing the given rows as formattedString
s
-
writeRowsToString
public final java.util.List<java.lang.String> writeRowsToString(java.util.Collection<java.lang.Object[]> rows)
Iterates over all records and writes them to aList
ofString
. Note this method will not use theRowWriterProcessor
. UseprocessRecords(Iterable)
for that.- Parameters:
rows
- the rows to be written to aList
ofString
.- Returns:
- a
List
containing the given rows as formattedString
s
-
writeStringRowsToString
public final java.util.List<java.lang.String> writeStringRowsToString(java.util.Collection<java.lang.String[]> rows)
Iterates over all records and writes them to aList
ofString
. Note this method will not use theRowWriterProcessor
. UseprocessRecords(Iterable)
for that.- Parameters:
rows
- the rows to be written to aList
ofString
.- Returns:
- a
List
containing the given rows as formattedString
s
-
writeRecordsToString
public final java.util.List<java.lang.String> writeRecordsToString(java.util.Collection<? extends Record> rows)
Iterates over all records and writes them to aList
ofString
. Note this method will not use theRowWriterProcessor
. UseprocessRecords(Iterable)
for that.- Parameters:
rows
- the rows to be written to aList
ofString
.- Returns:
- a
List
containing the given rows as formattedString
s
-
writeRowToString
public final java.lang.String writeRowToString(java.util.Collection<?> row)
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
String
containing the information of the given record
-
writeRowToString
public final java.lang.String writeRowToString(java.lang.String[] row)
Writes the data given for an individual record to aString
. If the given data is null or empty, andCommonSettings.getSkipEmptyLines()
is true,null
will be returned In case of any errors, aTextWritingException
will 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
String
containing the information of the given record
-
writeRecordToString
public final <T extends Record> java.lang.String writeRecordToString(T row)
Writes the data given for an individual record to aString
. If the given data is null or empty, andCommonSettings.getSkipEmptyLines()
is true,null
will be returned In case of any errors, aTextWritingException
will 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
String
containing the information of the given record
-
writeRowToString
public final java.lang.String writeRowToString(java.lang.Object... row)
Writes the data given for an individual record to aString
. If the given data is null or empty, andCommonSettings.getSkipEmptyLines()
is true,null
will be returned In case of any errors, aTextWritingException
will 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
String
containing the information of the given record
-
adjustRowLength
private java.lang.Object[] adjustRowLength(java.lang.Object[] row)
-
commentRowToString
public final java.lang.String commentRowToString(java.lang.String comment)
Writes a comment row to aString
- Parameters:
comment
- the contents to be written as a comment to aString
.- Returns:
- a formatted
String
containing the comment.
-
internalWriteRowToString
private java.lang.String 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 ofrowAppender
depend on the concrete implementation ofprocessRow(Object[])
- Returns:
- a formatted
String
containing the comment.
-
writeValuesToString
public final java.lang.String writeValuesToString()
Writes the contents accumulated in an internal in-memory row (usingor #addValue()
as aString
- Returns:
- a formatted
String
containing 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 theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
. The output will remain open for further writing. ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.
-
processValuesToString
public final java.lang.String processValuesToString()
Writes the contents accumulated in an internal in-memory row (usingor #addValue()
to aString
The objects added to this row will be processed with theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
. The output will remain open for further writing. ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Returns:
- a formatted
String
containing the result produced by theRowWriterProcessor
using 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
private <K> void writeValuesFromMap(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
Writes values from an implementation ofMap
to 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
private void setHeadersFromMap(java.util.Map<?,?> map, boolean keys)
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
public final java.lang.String writeRowToString(java.util.Map<?,?> rowData)
Writes the values of a given map to aString
formatted 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
String
containing the given data as a formattedString
-
writeRow
public final void writeRow(java.util.Map<?,?> rowData)
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
public final <K> java.lang.String writeRowToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
Writes the values of a given map to aString
formatted 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
String
containing the given data as a formattedString
-
writeRow
public final <K> void writeRow(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
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
public final <K,I extends java.lang.Iterable<?>> java.util.List<java.lang.String> writeRowsToString(java.util.Map<K,I> rowData)
Writes the values of a given map to aList
ofString
formatted 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
.Null
will 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 aList
ofString
.- Returns:
- a
List
of formattedString
, eachString
representing one successful iteration over at least one element of the iterators in the map.
-
writeRows
public final <K,I extends java.lang.Iterable<?>> void writeRows(java.util.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
.Null
will 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 java.lang.Iterable<?>> java.util.List<java.lang.String> writeRowsToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData)
Writes the values of a given map to aList
ofString
formatted 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
.Null
will 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 aList
ofString
.- Returns:
- a
List
of formattedString
, eachString
representing one successful iteration over at least one element of the iterators in the map.
-
writeRows
public final <K,I extends java.lang.Iterable<?>> void writeRows(java.util.Map<K,java.lang.String> headerMapping, java.util.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
.Null
will 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 java.lang.Iterable<?>> void writeRows(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData, java.util.List<java.lang.String> outputList, boolean useRowProcessor)
Writes the values of a given map to aList
ofString
formatted 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
.Null
will 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 aList
ofString
.outputList
- an outputList
to fill with formattedString
s, eachString
representing one successful iteration over at least one element of the iterators in the map.
-
writeStringRowsToString
public final <K> java.util.List<java.lang.String> writeStringRowsToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.String[]> rowData)
Writes the values of a given map to aList
ofString
formatted 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
.Null
will 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 aList
ofString
.- Returns:
- a
List
of formattedString
, eachString
representing one successful iteration over at least one element of the iterators in the map.
-
writeRecordsToString
public final <K> java.util.List<java.lang.String> writeRecordsToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,? extends Record> rowData)
Writes the values of a given map to aList
ofString
formatted 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
.Null
will 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 aList
ofString
.- Returns:
- a
List
of formattedString
, eachString
representing one successful iteration over at least one element of the iterators in the map.
-
writeStringRows
public final <K> void writeStringRows(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.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. A new record will be created each time at least oneIterator.hasNext()
returnstrue
.Null
will 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
public final <K> void writeRecords(java.util.Map<K,java.lang.String> headerMapping, java.util.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. A new record will be created each time at least oneIterator.hasNext()
returnstrue
.Null
will 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> java.util.List<java.lang.String> writeObjectRowsToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.Object[]> rowData)
Writes the values of a given map to aList
ofString
formatted 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
.Null
will 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 aList
ofString
.- Returns:
- a
List
of formattedString
, eachString
representing one successful iteration over at least one element of the iterators in the map.
-
writeObjectRows
public final <K> void writeObjectRows(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.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. A new record will be created each time at least oneIterator.hasNext()
returnstrue
.Null
will 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
private <K> java.util.Map<K,java.lang.Iterable<java.lang.Object>> wrapObjectArray(java.util.Map<K,java.lang.Object[]> rowData)
-
wrapStringArray
private <K> java.util.Map<K,java.lang.Iterable<java.lang.String>> wrapStringArray(java.util.Map<K,java.lang.String[]> rowData)
-
wrapRecordValues
private <K> java.util.Map<K,java.lang.Iterable<java.lang.String>> wrapRecordValues(java.util.Map<K,? extends Record> rowData)
-
writeObjectRowsAndClose
public final <K> void writeObjectRowsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.Object[]> 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
.Null
will 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
public final <K> void writeStringRowsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.String[]> 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
.Null
will 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(java.util.Map<K,java.lang.String> headerMapping, java.util.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
.Null
will 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
public final <K> void writeObjectRowsAndClose(java.util.Map<K,java.lang.Object[]> 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
.Null
will 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
public final <K> void writeStringRowsAndClose(java.util.Map<K,java.lang.String[]> 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
.Null
will 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
public final <K> void writeRecordsAndClose(java.util.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
.Null
will 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 java.lang.Iterable<?>> void writeRowsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.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
.Null
will 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
public final <K,I extends java.lang.Iterable<?>> void writeRowsAndClose(java.util.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
.Null
will 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
public final java.lang.String processRecordToString(java.util.Map<?,?> rowData)
Processes the values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result intoString
formatted according to the specified output format. ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Parameters:
rowData
- the map whose values will be used to generate aList
ofString
.- Returns:
- a
String
containing the given data as a formattedString
-
processRecord
public final void processRecord(java.util.Map<?,?> rowData)
Processes the values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result into a new output record ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Parameters:
rowData
- the map whose values will be used to generate aList
ofString
.
-
processRecordToString
public final <K> java.lang.String processRecordToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
Processes the values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result intoString
formatted according to the specified output format. ATextWritingException
will be thrown if noRowWriterProcessor
is 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 aList
ofString
.- Returns:
- a
String
containing the given data as a formattedString
-
processRecord
public final <K> void processRecord(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
Processes the values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result into a new output record ATextWritingException
will be thrown if noRowWriterProcessor
is 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 aList
ofString
.
-
processRecordsToString
public final <K,I extends java.lang.Iterable<?>> java.util.List<java.lang.String> processRecordsToString(java.util.Map<K,I> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result into aList
ofString
formatted 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. ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Type Parameters:
K
- the key typeI
- the iterable type- Parameters:
rowData
- the map whose values will be used to generate aList
ofString
.- Returns:
- a
List
of formattedString
, eachString
representing one successful iteration over at least one element of the iterators in the map.
-
processRecords
public final <K,I extends java.lang.Iterable<?>> void processRecords(java.util.Map<K,I> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes all values to the output . The output will remain open for further write operations. ATextWritingException
will be thrown if noRowWriterProcessor
is 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 java.lang.Iterable<?>> java.util.List<java.lang.String> processRecordsToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result into aList
ofString
formatted 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. ATextWritingException
will be thrown if noRowWriterProcessor
is 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 aList
ofString
.- Returns:
- a
List
of formattedString
, eachString
representing one successful iteration over at least one element of the iterators in the map.
-
processRecords
public final <K,I extends java.lang.Iterable<?>> void processRecords(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes all values to the output . The output will remain open for further write operations. ATextWritingException
will be thrown if noRowWriterProcessor
is 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
public final <K> java.util.List<java.lang.String> processObjectRecordsToString(java.util.Map<K,java.lang.Object[]> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result into aList
ofString
formatted 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. ATextWritingException
will be thrown if noRowWriterProcessor
is provided byCommonWriterSettings.getRowWriterProcessor()
.- Type Parameters:
K
- the key type- Parameters:
rowData
- the map whose values will be used to generate aList
ofString
.- Returns:
- a
List
of formattedString
, eachString
representing one successful iteration over at least one element of the iterators in the map.
-
processObjectRecordsToString
public final <K> java.util.List<java.lang.String> processObjectRecordsToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.Object[]> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
and writes the result into aList
ofString
formatted 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. ATextWritingException
will be thrown if noRowWriterProcessor
is 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 aList
ofString
.- Returns:
- a
List
of formattedString
, eachString
representing one successful iteration over at least one element of the iterators in the map.
-
processObjectRecords
public final <K> void processObjectRecords(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.Object[]> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes all values to the output . The output will remain open for further write operations. ATextWritingException
will be thrown if noRowWriterProcessor
is 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(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.Object[]> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes all values to the output and closes the writer. ATextWritingException
will be thrown if noRowWriterProcessor
is 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(java.util.Map<K,java.lang.Object[]> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided byCommonWriterSettings.getRowWriterProcessor()
, then writes all values to the output and closes the writer. ATextWritingException
will be thrown if noRowWriterProcessor
is 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 java.lang.Iterable<?>> void processRecordsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided 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
.Null
will be written when a iterator has been fully read. ATextWritingException
will be thrown if noRowWriterProcessor
is 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
public final <K,I extends java.lang.Iterable<?>> void processRecordsAndClose(java.util.Map<K,I> rowData)
Processes the data in all values of a map using theRowWriterProcessor
provided 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
.Null
will be written when a iterator has been fully read. ATextWritingException
will be thrown if noRowWriterProcessor
is 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
private java.lang.Object[] getContent(java.lang.Object[] tmp)
-
getContent
private java.lang.String getContent(java.lang.CharSequence tmp)
-
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:
true
if 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.
-
-