S
- The specific writer settings configuration class, which can potentially provide additional configuration options supported by the writer implementation.public abstract class AbstractWriter<S extends CommonWriterSettings<?>>
extends java.lang.Object
CommonWriterSettings
, and delegates the writing algorithm implementation to its subclasses through the abstract method processRow(Object[])
The following (absolutely required) attributes are exposed to subclasses:
WriterCharAppender
): the character writer that appends characters from a given input into an internal bufferModifier and Type | Field and Description |
---|---|
protected WriterCharAppender |
appender |
private boolean |
columnReorderingEnabled |
private 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 and Description |
---|
AbstractWriter(java.io.File file,
java.nio.charset.Charset encoding,
S settings)
All writers must support, at the very least, the settings provided by
CommonWriterSettings . |
AbstractWriter(java.io.File file,
S settings)
All writers must support, at the very least, the settings provided by
CommonWriterSettings . |
AbstractWriter(java.io.File file,
java.lang.String encoding,
S settings)
All writers must support, at the very least, the settings provided by
CommonWriterSettings . |
AbstractWriter(java.io.OutputStream output,
java.nio.charset.Charset encoding,
S settings)
All writers must support, at the very least, the settings provided by
CommonWriterSettings . |
AbstractWriter(java.io.OutputStream output,
S settings)
All writers must support, at the very least, the settings provided by
CommonWriterSettings . |
AbstractWriter(java.io.OutputStream output,
java.lang.String encoding,
S settings)
All writers must support, at the very least, the settings provided by
CommonWriterSettings . |
AbstractWriter(S settings)
All writers must support, at the very least, the settings provided by
CommonWriterSettings . |
AbstractWriter(java.io.Writer writer,
S settings)
All writers must support, at the very least, the settings provided by
CommonWriterSettings . |
Modifier and Type | Method and 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.util.Collection<?> values)
Writes a sequence of values to a row in memory.
|
void |
addValues(java.lang.Object... 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 row
|
protected void |
appendValueToRow()
Appends the processed sequence of characters in
appender to the output row. |
void |
close()
Closes the
Writer 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 a
String |
void |
discardValues()
Discards the contents written to the internal in-memory row (using
or #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 the
Writer 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 original
headers array defined in this writer |
long |
getRecordCount()
Returns the number of records written to the output so far
|
private NormalizedString[] |
getRowProcessorHeaders() |
protected java.lang.String |
getStringValue(java.lang.Object element)
Converts a given object to its String representation for writing to a
String
If the object is null, then nullValue is returned.
If the String representation of this object is an empty String, then emptyValue is returned
|
protected 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 the
RowWriterProcessor provided by CommonWriterSettings.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 the
RowWriterProcessor provided by CommonWriterSettings.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 the
RowWriterProcessor provided by CommonWriterSettings.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 the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into a List of String 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 the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into a List of String formatted to according to the specified output format. |
void |
processRecord(java.util.Map<?,?> rowData)
Processes the values of a map using the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into a new output record
A TextWritingException will be thrown if no RowWriterProcessor is provided by CommonWriterSettings.getRowWriterProcessor() . |
<K> void |
processRecord(java.util.Map<K,java.lang.String> headerMapping,
java.util.Map<K,?> rowData)
Processes the values of a map using the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into a new output record
A TextWritingException will be thrown if no RowWriterProcessor is provided by CommonWriterSettings.getRowWriterProcessor() . |
void |
processRecord(java.lang.Object... record)
Processes the data given for an individual record with the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , then writes it. |
void |
processRecord(java.lang.Object record)
Processes the data given for an individual record with the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , then writes it. |
<T extends Record> |
processRecord(T record) |
void |
processRecords(java.lang.Iterable<?> records)
Iterates over all records, processes each one with the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , and writes them. |
<K,I extends java.lang.Iterable<?>> |
processRecords(java.util.Map<K,I> rowData)
Processes the data in all values of a map using the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() ,
then writes all values to the output . |
<K,I extends java.lang.Iterable<?>> |
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 the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() ,
then writes all values to the output . |
void |
processRecords(java.lang.Object[] records)
Iterates over all records, processes each one with the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , and writes them. |
<T extends Record> |
processRecords(T[] records)
Iterates over all records, processes each one with the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , and writes them. |
void |
processRecordsAndClose(java.lang.Iterable<?> allRecords)
Iterates over all records, processes each one with the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , and writes them, then finally and closes the output
A TextWritingException will be thrown if no RowWriterProcessor is provided by CommonWriterSettings.getRowWriterProcessor() . |
<K,I extends java.lang.Iterable<?>> |
processRecordsAndClose(java.util.Map<K,I> rowData)
Processes the data in all values of a map using the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() ,
then writes all values to the output and closes the writer. |
<K,I extends java.lang.Iterable<?>> |
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 the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() ,
then writes all values to the output and closes the writer. |
void |
processRecordsAndClose(java.lang.Object[] allRecords)
Iterates over all records, processes each one with the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , and writes them, then finally and closes the output
A TextWritingException will be thrown if no RowWriterProcessor is provided by CommonWriterSettings.getRowWriterProcessor() . |
java.util.List<java.lang.String> |
processRecordsToString(java.lang.Iterable<?> records)
Iterates over all records, processes each one with the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , and writes them to a List of String . |
<K,I extends java.lang.Iterable<?>> |
processRecordsToString(java.util.Map<K,I> rowData)
Processes the data in all values of a map using the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into a List of String formatted to according to the specified output format. |
<K,I extends java.lang.Iterable<?>> |
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 the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into a List of String formatted to according to the specified output format. |
java.util.List<java.lang.String> |
processRecordsToString(java.lang.Object[] records)
Iterates over all records, processes each one with the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , and writes them them to a List of String . |
java.lang.String |
processRecordToString(java.util.Map<?,?> rowData)
Processes the values of a map using the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into String 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 the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into String formatted according to the specified output format. |
java.lang.String |
processRecordToString(java.lang.Object... record)
Processes the data given for an individual record with the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , then writes it to a String . |
java.lang.String |
processRecordToString(java.lang.Object record)
Processes the data given for an individual record with the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , then writes it. |
<T extends Record> |
processRecordToString(T record)
Processes the data given for an individual record with the
RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , then writes it to a String . |
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 (using
or #addValue() to a new record in the output. |
java.lang.String |
processValuesToString()
Writes the contents accumulated in an internal in-memory row (using
or #addValue() to a String
The objects added to this row will be processed with the RowWriterProcessor provided by CommonWriterSettings.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, a
TextWritingException is thrown, and the output Writer is closed. |
private TextWritingException |
throwExceptionAndClose(java.lang.String message,
java.lang.Object[] recordValues,
java.lang.Throwable cause)
In case of any exceptions, a
TextWritingException is thrown, and the output Writer is closed. |
private TextWritingException |
throwExceptionAndClose(java.lang.String message,
java.lang.String recordCharacters,
java.lang.Throwable cause)
In case of any exceptions, a
TextWritingException is thrown, and the output Writer is closed. |
private TextWritingException |
throwExceptionAndClose(java.lang.String message,
java.lang.Throwable cause)
In case of any exceptions, a
TextWritingException is thrown, and the output Writer 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 a
FixedWidthWriter whose
FixedWidthWriterSettings.getWriteLineSeparatorAfterRecord() evaluates to false . |
void |
writeHeaders()
Writes the headers defined in
CommonSettings.getHeaders()
A TextWritingException will be thrown if no headers were defined or if records were already written to the output. |
void |
writeHeaders(java.util.Collection<?> headers)
Writes the given collection of headers to the output.
|
void |
writeHeaders(java.lang.String... headers)
Writes the given collection of headers to the output.
|
java.lang.String |
writeHeadersToString()
Writes the headers defined in
CommonSettings.getHeaders() to a String |
java.lang.String |
writeHeadersToString(java.util.Collection<?> headers)
Writes the given collection of headers to a
String
A TextWritingException will be thrown if no headers were defined. |
java.lang.String |
writeHeadersToString(java.lang.String... headers)
Writes the given collection of headers to a
String
A TextWritingException will be thrown if no headers were defined or if records were already written to a String |
<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 a
List of String formatted to according to the specified output format. |
<T extends Record> |
writeRecord(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 a
List of String . |
<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 a
List of String formatted to according to the specified output format. |
<T extends Record> |
writeRecordToString(T row)
Writes the data given for an individual record to a
String . |
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 the
RowWriterProcessor . |
<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 the
RowWriterProcessor . |
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 |
writeRows(java.util.Collection<java.lang.Object[]> rows)
Iterates over all records and writes them to the output.
|
<C extends java.util.Collection<?>> |
writeRows(java.lang.Iterable<C> rows)
Iterates over all records and writes them to the output.
|
<K,I extends java.lang.Iterable<?>> |
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.
|
<K,I extends java.lang.Iterable<?>> |
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.
|
private <K,I extends java.lang.Iterable<?>> |
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 a
List of String formatted to according to the specified output format. |
void |
writeRows(java.lang.Object[][] rows)
Iterates over all records and writes them to the output.
|
void |
writeRowsAndClose(java.util.Collection<java.lang.Object[]> allRows)
Iterates over all records, writes them and closes the output.
|
<C extends java.util.Collection<?>> |
writeRowsAndClose(java.lang.Iterable<C> allRows)
Iterates over all records, writes them and closes the output.
|
<K,I extends java.lang.Iterable<?>> |
writeRowsAndClose(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<?>> |
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.
|
void |
writeRowsAndClose(java.lang.Object[][] allRows)
Iterates over all records, writes them and closes the output.
|
java.util.List<java.lang.String> |
writeRowsToString(java.util.Collection<java.lang.Object[]> rows)
Iterates over all records and writes them to a
List of String . |
<C extends java.util.Collection<?>> |
writeRowsToString(java.lang.Iterable<C> rows)
Iterates over all records and writes them to a
List of String . |
<K,I extends java.lang.Iterable<?>> |
writeRowsToString(java.util.Map<K,I> rowData)
Writes the values of a given map to a
List of String formatted to according to the specified output format. |
<K,I extends java.lang.Iterable<?>> |
writeRowsToString(java.util.Map<K,java.lang.String> headerMapping,
java.util.Map<K,I> rowData)
Writes the values of a given map to a
List of String formatted to according to the specified output format. |
java.util.List<java.lang.String> |
writeRowsToString(java.lang.Object[][] rows)
Iterates over all records and writes them to a
List of String . |
java.lang.String |
writeRowToString(java.util.Collection<?> row)
Writes the data given for an individual record to a
String . |
java.lang.String |
writeRowToString(java.util.Map<?,?> rowData)
Writes the values of a given map to a
String 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 a
String 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 a
String . |
java.lang.String |
writeRowToString(java.lang.String[] row)
Writes the data given for an individual record to a
String . |
void |
writeStringRows(java.util.Collection<java.lang.String[]> rows)
Iterates over all records and writes them to the output.
|
<C extends java.util.Collection<?>> |
writeStringRows(java.lang.Iterable<C> 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.
|
java.util.List<java.lang.String> |
writeStringRowsToString(java.util.Collection<java.lang.String[]> rows)
Iterates over all records and writes them to a
List of String . |
<C extends java.util.Collection<?>> |
writeStringRowsToString(java.lang.Iterable<C> rows)
Iterates over all records and writes them to a
List of String . |
<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 a
List of String 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 of
Map to a partial output record, ready to be
written to the output. |
void |
writeValuesToRow()
Writes the contents accumulated in an internal in-memory row (using
or #writeValue() to a new record in the output. |
java.lang.String |
writeValuesToString()
Writes the contents accumulated in an internal in-memory row (using
or #addValue() as a String |
private final RowWriterProcessor writerProcessor
private java.io.Writer writer
private final boolean skipEmptyLines
private final char comment
private final WriterCharAppender rowAppender
private final boolean isHeaderWritingEnabled
private java.lang.Object[] outputRow
private int[] indexesToWrite
private final char[] lineSeparator
protected NormalizedString[] headers
protected long recordCount
protected final java.lang.String nullValue
protected final java.lang.String emptyValue
protected final WriterCharAppender appender
private final java.lang.Object[] partialLine
private int partialLineIndex
private java.util.Map<NormalizedString[],java.util.Map<NormalizedString,java.lang.Integer>> headerIndexes
private int largestRowLength
protected boolean writingHeaders
protected boolean[] headerTrimFlags
private NormalizedString[] dummyHeaderRow
protected boolean expandRows
private boolean usingSwitch
private boolean enableNewlineAfterRecord
protected boolean usingNullOrEmptyValue
protected final int whitespaceRangeStart
private final boolean columnReorderingEnabled
protected boolean ignoreLeading
protected boolean ignoreTrailing
private final CommonSettings<DummyFormat> internalSettings
private final int errorContentLength
public AbstractWriter(S settings)
CommonWriterSettings
. The AbstractWriter requires its configuration to be properly initialized.
Important: by not providing an instance of Writer
to this constructor, only the operations that write to Strings are available.settings
- the writer configurationpublic AbstractWriter(java.io.File file, S settings)
CommonWriterSettings
. The AbstractWriter requires its configuration to be properly initialized.file
- the output file that will be written with the format-specific records as defined by subclasses of AbstractWriter
.settings
- the writer configurationpublic AbstractWriter(java.io.File file, java.lang.String encoding, S settings)
CommonWriterSettings
. The AbstractWriter requires its configuration to be properly initialized.file
- the output file that will be written with the format-specific records as defined by subclasses of AbstractWriter
.encoding
- the encoding of the filesettings
- the writer configurationpublic AbstractWriter(java.io.File file, java.nio.charset.Charset encoding, S settings)
CommonWriterSettings
. The AbstractWriter requires its configuration to be properly initialized.file
- the output file that will be written with the format-specific records as defined by subclasses of AbstractWriter
.encoding
- the encoding of the filesettings
- the writer configurationpublic AbstractWriter(java.io.OutputStream output, S settings)
CommonWriterSettings
. The AbstractWriter requires its configuration to be properly initialized.output
- the output stream that will be written with the format-specific records as defined by subclasses of AbstractWriter
.settings
- the writer configurationpublic AbstractWriter(java.io.OutputStream output, java.lang.String encoding, S settings)
CommonWriterSettings
. The AbstractWriter requires its configuration to be properly initialized.output
- the output stream that will be written with the format-specific records as defined by subclasses of AbstractWriter
.encoding
- the encoding of the streamsettings
- the writer configurationpublic AbstractWriter(java.io.OutputStream output, java.nio.charset.Charset encoding, S settings)
CommonWriterSettings
. The AbstractWriter requires its configuration to be properly initialized.output
- the output stream that will be written with the format-specific records as defined by subclasses of AbstractWriter
.encoding
- the encoding of the streamsettings
- the writer configurationpublic AbstractWriter(java.io.Writer writer, S settings)
CommonWriterSettings
. The AbstractWriter requires its configuration to be properly initialized.writer
- the output resource that will receive the format-specific records as defined by subclasses of AbstractWriter
.settings
- the writer configurationprotected void enableNewlineAfterRecord(boolean enableNewlineAfterRecord)
protected abstract void initialize(S settings)
settings
- the settings object specific to the format being written.private void updateIndexesToWrite(CommonSettings<?> settings)
public void updateFieldSelection(java.lang.String... newFieldSelection)
newFieldSelection
- the new selection of fields to write.public void updateFieldSelection(java.lang.Integer... newFieldSelectionByIndex)
newFieldSelectionByIndex
- the new selection of fields to write.public void updateFieldExclusion(java.lang.String... fieldsToExclude)
fieldsToExclude
- the selection of fields to exclude from the output.public void updateFieldExclusion(java.lang.Integer... fieldIndexesToExclude)
fieldIndexesToExclude
- the selection of fields to exclude from the output.private void submitRow(java.lang.Object[] row)
row
- the data to be written for a single record in the output.protected abstract void processRow(java.lang.Object[] row)
RowWriterProcessor
).
It then delegates the record to the writer-specific implementation defined by processRow(Object[])
. In general, an implementation of processRow(Object[])
will perform the following steps:
appender
object. The an individual value is processed, the appendValueToRow()
method must be called.
This will clear the accumulated value in appender
and add it to the output row.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 a
FixedWidthWriter
whose FixedWidthWriterSettings.getWriteLineSeparatorAfterRecord()
evaluates to false
. The newline character sequence will conform to what is specified in Format.getLineSeparator()
This cycle repeats until the writing process is stopped by the user or an error happens.
In case of errors, the unchecked exception TextWritingException
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.row
- the data to be written to the output in the expected format.CharAppender
,
CommonWriterSettings
protected final void appendValueToRow()
appender
to the output row.protected final void appendToRow(char ch)
ch
- the character to append to the output rowprotected final void appendToRow(char[] chars)
chars
- the sequence of characters to append to the output rowpublic final void writeHeaders()
CommonSettings.getHeaders()
A TextWritingException
will be thrown if no headers were defined or if records were already written to the output.public final void writeHeaders(java.util.Collection<?> headers)
TextWritingException
will be thrown if no headers were defined or if records were already written to the output.headers
- the headers to write to the output.public final void writeHeaders(java.lang.String... headers)
TextWritingException
will be thrown if no headers were defined or if records were already written to the output.headers
- the headers to write to the output.public final void processRecordsAndClose(java.lang.Iterable<?> allRecords)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, and writes them, then finally and closes the output
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.allRecords
- the records to be transformed by a RowWriterProcessor
and then written to the outputpublic final void processRecordsAndClose(java.lang.Object[] allRecords)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, and writes them, then finally and closes the output
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.allRecords
- the records to be transformed by a RowWriterProcessor
and then written to the outputpublic final void processRecords(java.lang.Iterable<?> records)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, and writes them.
The output will remain open for further writing.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.records
- the records to be transformed by a RowWriterProcessor
and then written to the outputpublic final void processRecords(java.lang.Object[] records)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, and writes them.
The output will remain open for further writing.
* A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.records
- the records to transformed by a RowWriterProcessor
and then written to the outputpublic final <T extends Record> void processRecords(T[] records)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, and writes them.
The output will remain open for further writing.
* A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.records
- the records to transformed by a RowWriterProcessor
and then written to the outputpublic final void processRecord(java.lang.Object... record)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, then writes it.
The output will remain open for further writing.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.record
- the information of a single record to be transformed by a RowWriterProcessor
and then written to the outputpublic final <T extends Record> void processRecord(T record)
public final void processRecord(java.lang.Object record)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, then writes it.
The output will remain open for further writing.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.record
- the information of a single record to be transformed by a RowWriterProcessor
and then written to the outputprivate NormalizedString[] getRowProcessorHeaders()
public final <C extends java.util.Collection<?>> void writeRowsAndClose(java.lang.Iterable<C> allRows)
RowWriterProcessor
. Use processRecordsAndClose(Iterable)
for that.C
- Collection of objects containing values of a rowallRows
- the rows to be written to the outputpublic final void writeRowsAndClose(java.util.Collection<java.lang.Object[]> allRows)
RowWriterProcessor
. Use processRecordsAndClose(Object[])
for that.allRows
- the rows to be written to the outputpublic final void writeStringRowsAndClose(java.util.Collection<java.lang.String[]> allRows)
RowWriterProcessor
. Use processRecordsAndClose(Iterable)
for that.allRows
- the rows to be written to the outputpublic final void writeRecordsAndClose(java.util.Collection<? extends Record> allRows)
RowWriterProcessor
. Use processRecordsAndClose(Iterable)
for that.allRows
- the rows to be written to the outputpublic final void writeRowsAndClose(java.lang.Object[][] allRows)
RowWriterProcessor
. Use processRecordsAndClose(Object[])
for that.allRows
- the rows to be written to the outputpublic final void writeRows(java.lang.Object[][] rows)
RowWriterProcessor
. Use processRecords(Object[])
for that.rows
- the rows to be written to the outputpublic final <C extends java.util.Collection<?>> void writeRows(java.lang.Iterable<C> rows)
RowWriterProcessor
. Use processRecords(Iterable)
for that.C
- Collection of objects containing values of a rowrows
- the rows to be written to the outputpublic final void writeStringRows(java.util.Collection<java.lang.String[]> rows)
RowWriterProcessor
. Use processRecords(Iterable)
for that.rows
- the rows to be written to the outputpublic final void writeRecords(java.util.Collection<? extends Record> rows)
RowWriterProcessor
. Use processRecords(Iterable)
for that.rows
- the rows to be written to the outputpublic final <C extends java.util.Collection<?>> void writeStringRows(java.lang.Iterable<C> rows)
RowWriterProcessor
. Use processRecords(Iterable)
for that.C
- Collection of objects containing values of a rowrows
- the rows to be written to the outputpublic final void writeRows(java.util.Collection<java.lang.Object[]> rows)
RowWriterProcessor
. Use processRecords(Iterable)
for that.rows
- the rows to be written to the outputpublic final void writeRow(java.util.Collection<?> row)
RowWriterProcessor
. Use processRecord(Object)
for that.row
- the information of a single record to be written to the outputpublic final void writeRow(java.lang.String[] row)
CommonSettings.getSkipEmptyLines()
is true, the input will be just ignored.
If CommonSettings.getSkipEmptyLines()
is false, then an empty row will be written to the output (as specified by writeEmptyRow()
).
In case of any errors, a TextWritingException
will be thrown and the Writer
given in the constructor will be closed.
Note this method will not use the RowWriterProcessor
. Use processRecord(Object)
for that.row
- the information of a single record to be written to the outputpublic final <T extends Record> void writeRecord(T row)
CommonSettings.getSkipEmptyLines()
is true, the input will be just ignored.
If CommonSettings.getSkipEmptyLines()
is false, then an empty row will be written to the output (as specified by writeEmptyRow()
).
In case of any errors, a TextWritingException
will be thrown and the Writer
given in the constructor will be closed.
Note this method will not use the RowWriterProcessor
. Use processRecord(Object)
for that.row
- the information of a single record to be written to the outputpublic final void writeRow(java.lang.Object... row)
CommonSettings.getSkipEmptyLines()
is true, the input will be just ignored.
If CommonSettings.getSkipEmptyLines()
is false, then an empty row will be written to the output (as specified by writeEmptyRow()
).
In case of any errors, a TextWritingException
will be thrown and the Writer
given in the constructor will be closed.
Note this method will not use the RowWriterProcessor
. Use processRecord(Object)
for that.row
- the information of a single record to be written to the outputprotected java.lang.Object[] expand(java.lang.Object[] row, int length, java.lang.Integer h2)
public final void writeRow(java.lang.String row)
FixedWidthWriter
whose
FixedWidthWriterSettings.getWriteLineSeparatorAfterRecord()
evaluates to false
.
The newline character sequence will conform to what is specified in Format.getLineSeparator()
The writer implementation has no control over the format of this content.
The output will remain open for further writing.row
- the line to be written to the outputpublic final void writeEmptyRow()
FixedWidthWriter
whose
FixedWidthWriterSettings.getWriteLineSeparatorAfterRecord()
evaluates to false
.
The newline character sequence will conform to what is specified in Format.getLineSeparator()
The output will remain open for further writing.public final void commentRow(java.lang.String comment)
FixedWidthWriter
whose
FixedWidthWriterSettings.getWriteLineSeparatorAfterRecord()
evaluates to false
.
The newline character sequence will conform to what is specified in Format.getLineSeparator()
The output will remain open for further writing.comment
- the contents to be written as a comment to the outputprivate <T> void fillOutputRow(T[] row)
row
- user-provided data which has to be rearranged to the expected record sequence before writing to the output.private void internalWriteRow()
Format.getLineSeparator()
The contents of rowAppender
depend on the concrete implementation of processRow(Object[])
protected static int skipLeadingWhitespace(int whitespaceRangeStart, java.lang.String element)
ch <= ' '
evaluates to true
whitespaceRangeStart
- starting range after which characters will be considered whitespaceelement
- the String to be scanned for leading whitespaces.public final void flush()
Writer
given in this class constructor.
An IllegalStateException will be thrown in case of any errors, and the writer will be closed.public final void close()
Writer
given in this class constructor.
An IllegalStateException will be thrown in case of any errors.private TextWritingException throwExceptionAndClose(java.lang.String message)
TextWritingException
is thrown, and the output Writer
is closed.message
- Description of the errorprivate TextWritingException throwExceptionAndClose(java.lang.String message, java.lang.Throwable cause)
TextWritingException
is thrown, and the output Writer
is closed.message
- Description of the errorcause
- the exception to be wrapped by a TextWritingException
private TextWritingException throwExceptionAndClose(java.lang.String message, java.lang.String recordCharacters, java.lang.Throwable cause)
TextWritingException
is thrown, and the output Writer
is closed.message
- Description of the errorrecordCharacters
- characters used to write to the output at the time the exception happenedcause
- the exception to be wrapped by a TextWritingException
private TextWritingException throwExceptionAndClose(java.lang.String message, java.lang.Object[] recordValues, java.lang.Throwable cause)
TextWritingException
is thrown, and the output Writer
is closed.message
- Description of the errorrecordValues
- values used to write to the output at the time the exception happenedcause
- the exception to be wrapped by a TextWritingException
protected java.lang.String getStringValue(java.lang.Object element)
String
nullValue
is returned.emptyValue
is returnedelement
- the object to be converted into a String.public final void addValues(java.lang.Object... values)
writeValuesToRow()
is called to flush
all values accumulated and effectively write a new record to the outputvalues
- the values to be writtenpublic final void addStringValues(java.util.Collection<java.lang.String> values)
writeValuesToRow()
is called to flush
all values accumulated and effectively write a new record to the outputvalues
- the values to be writtenpublic final void addValues(java.util.Collection<?> values)
writeValuesToRow()
is called to flush
all values accumulated and effectively write a new record to the outputvalues
- the values to be writtenpublic final void addValue(java.lang.Object value)
writeValuesToRow()
is called to flush
all values accumulated and effectively write a new record to the outputvalue
- the value to be writtenprivate void fillPartialLineToMatchHeaders()
public final void writeValuesToRow()
or #writeValue()
to a new record in the output.public final void addValue(int index, java.lang.Object value)
writeValuesToRow()
is called to flush
all values accumulated and effectively write a new record to the outputindex
- the position in the row that should receive the value.value
- the value to be writtenpublic final void addValue(java.lang.String headerName, java.lang.Object value)
writeValuesToRow()
is called to flush
all values accumulated and effectively write a new record to the outputheaderName
- the name of the column of the new row that should receive the value.value
- the value to be writtenprivate final void addValue(NormalizedString[] headersInContext, NormalizedString headerName, boolean ignoreOnMismatch, java.lang.Object value)
private int getFieldIndex(NormalizedString[] headersInContext, NormalizedString headerName, boolean ignoreOnMismatch)
headers
array defined in this writerheadersInContext
- 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.true
public final void discardValues()
or #writeValue()
.public final java.lang.String writeHeadersToString()
CommonSettings.getHeaders()
to a String
String
containing the headers defined in CommonSettings.getHeaders()
public final java.lang.String writeHeadersToString(java.util.Collection<?> headers)
String
A TextWritingException
will be thrown if no headers were defined.headers
- the headers to write to a String
String
containing the given headerspublic final java.lang.String writeHeadersToString(java.lang.String... headers)
String
A TextWritingException
will be thrown if no headers were defined or if records were already written to a String
headers
- the headers to write to a String
String
containing the given headerspublic final java.util.List<java.lang.String> processRecordsToString(java.lang.Iterable<?> records)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, and writes them to a List
of String
.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.records
- the records to be transformed by a RowWriterProcessor
and then written to a List
of String
.List
containing the information transformed from the given records as formatted String
spublic final java.util.List<java.lang.String> processRecordsToString(java.lang.Object[] records)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, and writes them them to a List
of String
.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.records
- the records to transformed by a RowWriterProcessor
and then written a String
.List
containing the information transformed from the given records as formatted String
spublic final java.lang.String processRecordToString(java.lang.Object... record)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, then writes it to a String
.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.record
- the information of a single record to be transformed by a RowWriterProcessor
and then written to a String
.String
containing the information transformed from the given recordpublic final <T extends Record> java.lang.String processRecordToString(T record)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, then writes it to a String
.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.record
- the information of a single record to be transformed by a RowWriterProcessor
and then written to a String
.String
containing the information transformed from the given recordpublic final java.lang.String processRecordToString(java.lang.Object record)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, then writes it.
The output will remain open for further writing.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.record
- the information of a single record to be transformed by a RowWriterProcessor
and then written to a String
.String
containing the information transformed from the given recordpublic final java.util.List<java.lang.String> writeRowsToString(java.lang.Object[][] rows)
List
of String
.
Note this method will not use the RowWriterProcessor
. Use processRecords(Object[])
for that.rows
- the rows to be written to a List
of String
.List
containing the given rows as formatted String
spublic final <C extends java.util.Collection<?>> java.util.List<java.lang.String> writeRowsToString(java.lang.Iterable<C> rows)
List
of String
.
Note this method will not use the RowWriterProcessor
. Use processRecords(Iterable)
for that.C
- Collection of objects containing values of a rowrows
- the rows to be written to a List
of String
.List
containing the given rows as formatted String
spublic final <C extends java.util.Collection<?>> java.util.List<java.lang.String> writeStringRowsToString(java.lang.Iterable<C> rows)
List
of String
.
Note this method will not use the RowWriterProcessor
. Use processRecords(Iterable)
for that.C
- Collection of objects containing values of a rowrows
- the rows to be written to a List
of String
.List
containing the given rows as formatted String
spublic final java.util.List<java.lang.String> writeRowsToString(java.util.Collection<java.lang.Object[]> rows)
List
of String
.
Note this method will not use the RowWriterProcessor
. Use processRecords(Iterable)
for that.rows
- the rows to be written to a List
of String
.List
containing the given rows as formatted String
spublic final java.util.List<java.lang.String> writeStringRowsToString(java.util.Collection<java.lang.String[]> rows)
List
of String
.
Note this method will not use the RowWriterProcessor
. Use processRecords(Iterable)
for that.rows
- the rows to be written to a List
of String
.List
containing the given rows as formatted String
spublic final java.util.List<java.lang.String> writeRecordsToString(java.util.Collection<? extends Record> rows)
List
of String
.
Note this method will not use the RowWriterProcessor
. Use processRecords(Iterable)
for that.rows
- the rows to be written to a List
of String
.List
containing the given rows as formatted String
spublic final java.lang.String writeRowToString(java.util.Collection<?> row)
String
.
Note this method will not use the RowWriterProcessor
. Use processRecord(Object)
for that.row
- the information of a single record to be written to a String
String
containing the information of the given recordpublic final java.lang.String writeRowToString(java.lang.String[] row)
String
.
If the given data is null or empty, and CommonSettings.getSkipEmptyLines()
is true, null
will be returned
In case of any errors, a TextWritingException
will be thrown.
Note this method will not use the RowWriterProcessor
. Use processRecord(Object)
for that.row
- the information of a single record to be written to a String
.String
containing the information of the given recordpublic final <T extends Record> java.lang.String writeRecordToString(T row)
String
.
If the given data is null or empty, and CommonSettings.getSkipEmptyLines()
is true, null
will be returned
In case of any errors, a TextWritingException
will be thrown.
Note this method will not use the RowWriterProcessor
. Use processRecord(Object)
for that.row
- the information of a single record to be written to a String
.String
containing the information of the given recordpublic final java.lang.String writeRowToString(java.lang.Object... row)
String
.
If the given data is null or empty, and CommonSettings.getSkipEmptyLines()
is true, null
will be returned
In case of any errors, a TextWritingException
will be thrown.
Note this method will not use the RowWriterProcessor
. Use processRecord(Object)
for that.row
- the information of a single record to be written to a String
.String
containing the information of the given recordprivate java.lang.Object[] adjustRowLength(java.lang.Object[] row)
public final java.lang.String commentRowToString(java.lang.String comment)
String
comment
- the contents to be written as a comment to a String
.String
containing the comment.private java.lang.String internalWriteRowToString()
Format.getLineSeparator()
The contents of rowAppender
depend on the concrete implementation of processRow(Object[])
String
containing the comment.public final java.lang.String writeValuesToString()
or #addValue()
as a String
String
containing the information accumulated in the internal in-memory row.public final void processValuesToRow()
or #addValue()
to a new record in the output.
The objects added to this row will be processed with the RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
.
The output will remain open for further writing.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.public final java.lang.String processValuesToString()
or #addValue()
to a String
The objects added to this row will be processed with the RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
.
The output will remain open for further writing.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.String
containing the result produced by the RowWriterProcessor
using the values accumulated in internal in-memory row.public final long getRecordCount()
private <K> void writeValuesFromMap(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
Map
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.K
- type of the key in both rowData and headerMapping maps.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.private void setHeadersFromMap(java.util.Map<?,?> map, boolean keys)
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.public final java.lang.String writeRowToString(java.util.Map<?,?> rowData)
String
formatted to according to the specified output format.
Note this method will not use the RowWriterProcessor
.rowData
- the map whose values will be used to generate a String
.String
containing the given data as a formatted String
public final void writeRow(java.util.Map<?,?> rowData)
RowWriterProcessor
.rowData
- the map whose values will be used to generate a new recordpublic final <K> java.lang.String writeRowToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
String
formatted to according to the specified output format.
Note this method will not use the RowWriterProcessor
.K
- the key typeheaderMapping
- 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 String
.String
containing the given data as a formatted String
public final <K> void writeRow(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
RowWriterProcessor
.K
- the key typeheaderMapping
- 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 recordpublic final <K,I extends java.lang.Iterable<?>> java.util.List<java.lang.String> writeRowsToString(java.util.Map<K,I> rowData)
List
of String
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 one Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeI
- the iterable typerowData
- the map whose values will be used to generate a List
of String
.List
of formatted String
, each String
representing one successful iteration over at least one
element of the iterators in the map.public final <K,I extends java.lang.Iterable<?>> void writeRows(java.util.Map<K,I> rowData)
Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeI
- the iterable typerowData
- the map whose values will be used to generate a number of output recordspublic 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)
List
of String
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 one Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeI
- the iterable typeheaderMapping
- 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 List
of String
.List
of formatted String
, each String
representing one successful iteration over at least one
element of the iterators in the map.public final <K,I extends java.lang.Iterable<?>> void writeRows(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData)
Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeI
- the iterable typeheaderMapping
- 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 recordsprivate <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)
List
of String
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 one Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeI
- the iterable typeheaderMapping
- 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 List
of String
.outputList
- an output List
to fill with formatted String
s, each String
representing
one successful iteration over at least one
element of the iterators in the map.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)
List
of String
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 one Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeheaderMapping
- 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 List
of String
.List
of formatted String
, each String
representing one successful iteration over at least one
element of the iterators in the map.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)
List
of String
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 one Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeheaderMapping
- 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 List
of String
.List
of formatted String
, each String
representing one successful iteration over at least one
element of the iterators in the map.public final <K> void writeStringRows(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.String[]> rowData)
Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeheaderMapping
- 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 recordspublic final <K> void writeRecords(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,? extends Record> rowData)
Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeheaderMapping
- 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 recordspublic 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)
List
of String
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 one Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeheaderMapping
- 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 List
of String
.List
of formatted String
, each String
representing one successful iteration over at least one
element of the iterators in the map.public final <K> void writeObjectRows(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.Object[]> rowData)
Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeheaderMapping
- 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 recordsprivate <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>> wrapStringArray(java.util.Map<K,java.lang.String[]> rowData)
private <K> java.util.Map<K,java.lang.Iterable<java.lang.String>> wrapRecordValues(java.util.Map<K,? extends Record> rowData)
public final <K> void writeObjectRowsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.Object[]> rowData)
Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeheaderMapping
- 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 recordspublic final <K> void writeStringRowsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.String[]> rowData)
Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeheaderMapping
- 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 recordspublic final <K> void writeRecordsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,? extends Record> rowData)
Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeheaderMapping
- 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 recordspublic final <K> void writeObjectRowsAndClose(java.util.Map<K,java.lang.Object[]> rowData)
Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typerowData
- the map whose values will be used to generate a number of output recordspublic final <K> void writeStringRowsAndClose(java.util.Map<K,java.lang.String[]> rowData)
Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typerowData
- the map whose values will be used to generate a number of output recordspublic final <K> void writeRecordsAndClose(java.util.Map<K,? extends Record> rowData)
Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typerowData
- the map whose values will be used to generate a number of output recordspublic final <K,I extends java.lang.Iterable<?>> void writeRowsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData)
Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeI
- the iterable typeheaderMapping
- 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 recordspublic final <K,I extends java.lang.Iterable<?>> void writeRowsAndClose(java.util.Map<K,I> rowData)
Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
Note this method will not use the RowWriterProcessor
.K
- the key typeI
- the iterable typerowData
- the map whose values will be used to generate a number of output recordspublic final java.lang.String processRecordToString(java.util.Map<?,?> rowData)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into String
formatted according to the specified output format.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.rowData
- the map whose values will be used to generate a List
of String
.String
containing the given data as a formatted String
public final void processRecord(java.util.Map<?,?> rowData)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into a new output record
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.rowData
- the map whose values will be used to generate a List
of String
.public final <K> java.lang.String processRecordToString(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into String
formatted according to the specified output format.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.K
- the key typeheaderMapping
- 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 List
of String
.String
containing the given data as a formatted String
public final <K> void processRecord(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,?> rowData)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into a new output record
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.K
- the key typeheaderMapping
- 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 List
of String
.public final <K,I extends java.lang.Iterable<?>> java.util.List<java.lang.String> processRecordsToString(java.util.Map<K,I> rowData)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into a List
of String
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 TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.K
- the key typeI
- the iterable typerowData
- the map whose values will be used to generate a List
of String
.List
of formatted String
, each String
representing one successful iteration over at least one
element of the iterators in the map.public final <K,I extends java.lang.Iterable<?>> void processRecords(java.util.Map<K,I> rowData)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
,
then writes all values to the output .
The output will remain open for further write operations.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.K
- the key typeI
- the iterable typerowData
- the map whose values will be used to generate a number of output recordspublic 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)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into a List
of String
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 TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.K
- the key typeI
- the iterable typeheaderMapping
- 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 List
of String
.List
of formatted String
, each String
representing one successful iteration over at least one
element of the iterators in the map.public final <K,I extends java.lang.Iterable<?>> void processRecords(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
,
then writes all values to the output .
The output will remain open for further write operations.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.K
- the key typeI
- the iterable typeheaderMapping
- 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 recordspublic final <K> java.util.List<java.lang.String> processObjectRecordsToString(java.util.Map<K,java.lang.Object[]> rowData)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into a List
of String
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 TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.K
- the key typerowData
- the map whose values will be used to generate a List
of String
.List
of formatted String
, each String
representing one successful iteration over at least one
element of the iterators in the map.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)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
and writes the result into a List
of String
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 TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.K
- the key typeheaderMapping
- 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 List
of String
.List
of formatted String
, each String
representing one successful iteration over at least one
element of the iterators in the map.public final <K> void processObjectRecords(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.Object[]> rowData)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
,
then writes all values to the output .
The output will remain open for further write operations.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.K
- the key typeheaderMapping
- 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 recordspublic final <K> void processObjectRecordsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,java.lang.Object[]> rowData)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
,
then writes all values to the output and closes the writer.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.K
- the key typeheaderMapping
- 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 recordspublic final <K> void processObjectRecordsAndClose(java.util.Map<K,java.lang.Object[]> rowData)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
,
then writes all values to the output and closes the writer.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.K
- the key typerowData
- the map whose values will be used to generate a number of output recordspublic final <K,I extends java.lang.Iterable<?>> void processRecordsAndClose(java.util.Map<K,java.lang.String> headerMapping, java.util.Map<K,I> rowData)
RowWriterProcessor
provided by CommonWriterSettings.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 one Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.K
- the key typeI
- the iterable typeheaderMapping
- 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 recordspublic final <K,I extends java.lang.Iterable<?>> void processRecordsAndClose(java.util.Map<K,I> rowData)
RowWriterProcessor
provided by CommonWriterSettings.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 one Iterator.hasNext()
returns true
. Null
will be written
when a iterator has been fully read.
A TextWritingException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.K
- the key typeI
- the iterable typerowData
- the map whose values will be used to generate a number of output recordsprivate java.lang.Object[] getContent(java.lang.Object[] tmp)
private java.lang.String getContent(java.lang.CharSequence tmp)
protected final boolean allowTrim(int fieldIndex)
' a '
and
'a'
will become the same value if the spaces are removed)fieldIndex
- index of the field to be written.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.