Class RowWriterProcessorSwitch
java.lang.Object
com.univocity.parsers.common.processor.RowWriterProcessorSwitch
- All Implemented Interfaces:
RowWriterProcessor<Object>
- Direct Known Subclasses:
OutputValueSwitch
A special
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.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
private NormalizedString[]
private String[]
private RowWriterProcessor
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract String
protected NormalizedString[]
Returns the headers in use by the current row writer processor implementation, which can vary among row writer processors.abstract NormalizedString[]
getHeaders
(Object input) Returns the sequence of headers to use for processing an input record.abstract NormalizedString[]
getHeaders
(Map headerMapping, 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.protected int[]
Returns the indexes in use by the current row writer processor implementation, which can vary among row writer processors.final int
Returns the minimum row length based on the number of headers and index sizesvoid
rowProcessorSwitched
(RowWriterProcessor<?> from, RowWriterProcessor<?> to) Notifies a change of row writer processor implementation.protected abstract RowWriterProcessor<?>
switchRowProcessor
(Object row) Analyzes an output row to determine whether or not the row writer processor implementation must be changedObject[]
write
(Object input, NormalizedString[] headers, int[] indicesToWrite) Converts the given input into an Object array that is suitable for writing.Object[]
-
Field Details
-
selectedRowWriterProcessor
-
minimumRowLength
private int minimumRowLength -
normalizedHeaders
-
previousHeaders
-
-
Constructor Details
-
RowWriterProcessorSwitch
public RowWriterProcessorSwitch()
-
-
Method Details
-
switchRowProcessor
Analyzes an output row to determine whether or not the row writer processor implementation must be changed- Parameters:
row
- a record with data to be written to the output- Returns:
- the row writer processor implementation to use. If it is not the same as the one used by the previous row,
the returned row writer processor will be used, and the
rowProcessorSwitched(RowWriterProcessor, RowWriterProcessor)
method will be called.
-
getHeaders
Returns the headers in use by the current row writer processor implementation, which can vary among row writer processors. Ifnull
, the headers defined inCommonSettings.getHeaders()
will be returned.- Returns:
- the current sequence of headers to use.
-
getIndexes
protected int[] getIndexes()Returns the indexes in use by the current row writer processor implementation, which can vary among row writer processors. Ifnull
, the indexes of fields that have been selected usingCommonSettings.selectFields(String...)
orCommonSettings.selectIndexes(Integer...)
will be returned.- Returns:
- the current sequence of indexes to use.
-
rowProcessorSwitched
Notifies a change of row writer processor implementation. Users are expected to override this method to receive the notification.- Parameters:
from
- the row writer processor previously in useto
- the new row writer processor to use to continue processing the output rows.
-
getHeaders
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. This is useful when the input map has keys will generate unwanted header names.- Parameters:
headerMapping
- an optional map associating keys of the rowData map with expected header namesmapInput
- the record data- Returns:
- the sequence of headers to use when processing the given input map.
-
getHeaders
Returns the sequence of headers to use for processing an input record.- Parameters:
input
- the record data- Returns:
- the sequence of headers to use when processing the given record.
-
describeSwitch
-
getMinimumRowLength
public final int getMinimumRowLength()Returns the minimum row length based on the number of headers and index sizes- Returns:
- the minimum length a row must have in order to be sent to the output
-
write
-
write
Description copied from interface:RowWriterProcessor
Converts the given input into an Object array that is suitable for writing. Used by format-specific writers that extendAbstractWriter
.- Specified by:
write
in interfaceRowWriterProcessor<Object>
- Parameters:
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 inCommonSettings.getHeaders()
indicesToWrite
- The indexes of the headers that are actually being written. May be null if no fields have been selected usingCommonSettings.selectFields(String...)
orCommonSettings.selectIndexes(Integer...)
- Returns:
- an Object array that is suitable for writing. If null or an empty array is returned then the writer might either skip this value or write an empty record (if
CommonSettings.getSkipEmptyLines()
is false) - See Also:
-