public abstract class RowWriterProcessorSwitch extends java.lang.Object implements RowWriterProcessor<java.lang.Object>
RowWriterProcessor
implementation that combines and allows switching among different
RowWriterProcessors. Concrete implementations of this class
are expected to implement the switchRowProcessor(T)
method and analyze the input row
to determine whether or not the current RowWriterProcessor
implementation must be changed to handle a special
circumstance (determined by the concrete implementation) such as a different row format.
When the row writer processor is switched, the rowProcessorSwitched(RowWriterProcessor, RowWriterProcessor)
will be called, and must be overridden, to notify the change to the user.Modifier and Type | Field and Description |
---|---|
private int |
minimumRowLength |
private RowWriterProcessor |
selectedRowWriterProcessor |
Constructor and Description |
---|
RowWriterProcessorSwitch() |
Modifier and Type | Method and Description |
---|---|
protected abstract java.lang.String |
describeSwitch() |
protected java.lang.String[] |
getHeaders()
Returns the headers in use by the current row writer processor implementation, which can vary among row writer processors.
|
abstract java.lang.String[] |
getHeaders(java.util.Map headerMapping,
java.util.Map mapInput)
Returns the sequence of headers to use for processing an input record represented by a map
A map of headers can be optionally provided to assign a name to the keys of the input map.
|
abstract java.lang.String[] |
getHeaders(java.lang.Object input)
Returns the sequence of headers to use for processing an input record.
|
protected int[] |
getIndexes()
Returns the indexes in use by the current row writer processor implementation, which can vary among row writer processors.
|
int |
getMinimumRowLength()
Returns the minimum row length based on the number of headers and index sizes
|
void |
rowProcessorSwitched(RowWriterProcessor<?> from,
RowWriterProcessor<?> to)
Notifies a change of row writer processor implementation.
|
protected abstract RowWriterProcessor<?> |
switchRowProcessor(java.lang.Object row)
Analyzes an output row to determine whether or not the row writer processor implementation must be changed
|
java.lang.Object[] |
write(java.lang.Object input,
java.lang.String[] headers,
int[] indicesToWrite)
Converts the given input into an Object array that is suitable for writing.
|
private RowWriterProcessor selectedRowWriterProcessor
private int minimumRowLength
protected abstract RowWriterProcessor<?> switchRowProcessor(java.lang.Object row)
row
- a record with data to be written to the outputrowProcessorSwitched(RowWriterProcessor, RowWriterProcessor)
method
will be called.protected java.lang.String[] getHeaders()
null
, the headers defined in CommonSettings.getHeaders()
will be returned.protected int[] getIndexes()
null
, the indexes of fields that have been selected using CommonSettings.selectFields(String...)
or CommonSettings.selectIndexes(Integer...)
will be returned.public void rowProcessorSwitched(RowWriterProcessor<?> from, RowWriterProcessor<?> to)
from
- the row writer processor previously in useto
- the new row writer processor to use to continue processing the output rows.public abstract java.lang.String[] getHeaders(java.util.Map headerMapping, java.util.Map mapInput)
headerMapping
- an optional map associating keys of the rowData map with expected header namesmapInput
- the record datapublic abstract java.lang.String[] getHeaders(java.lang.Object input)
input
- the record dataprotected abstract java.lang.String describeSwitch()
public final int getMinimumRowLength()
public java.lang.Object[] write(java.lang.Object input, java.lang.String[] headers, int[] indicesToWrite)
RowWriterProcessor
AbstractWriter
.write
in interface RowWriterProcessor<java.lang.Object>
input
- The original input record that must be converted into an Object array before writing to an output.headers
- All field names used to produce records in a given destination. May be null if no headers have been defined in CommonSettings.getHeaders()
indicesToWrite
- The indexes of the headers that are actually being written. May be null if no fields have been selected using CommonSettings.selectFields(String...)
or CommonSettings.selectIndexes(Integer...)
CommonSettings.getSkipEmptyLines()
is false)CsvWriter
,
FixedWidthWriter
,
CommonSettings
,
AbstractWriter