Package com.univocity.parsers.common
Class ParserOutput
- java.lang.Object
-
- com.univocity.parsers.common.ParserOutput
-
public class ParserOutput extends java.lang.ObjectThe ParserOutput is the component that manages records parsed byAbstractParserand their values. It is solely responsible for deciding when:- parsed records should be reordered according to the fields selected in
CommonSettings - characters and values parsed in
AbstractParser.parseRecord()should be retained or discarded - input headers should be loaded from the records parsed in
AbstractParser.parseRecord()or fromCommonSettings.getHeaders()
AbstractParser.- See Also:
AbstractParser,CommonSettings
- parsed records should be reordered according to the fields selected in
-
-
Field Summary
Fields Modifier and Type Field Description CharAppenderappenderThe appender available to parsers for accumulating characters read from the input.private CharAppenderappenderInstanceprivate CharAppender[]appendersStores (shared) references toCharAppenderfor each potential column (as given byCommonSettings.getMaxColumns()).protected intcolumnKeeps track of the current column being parsed in the input.private booleancolumnReorderingEnabledSettingprivate booleancolumnsReorderedprivate booleancolumnsToExtractInitializedprivate longcurrentRecordprivate NormalizedString[]headersprivate java.lang.String[]headerStringsprivate java.lang.StringnullValue(package private) java.lang.String[]parsedHeadersHeaders parsed from the input whenCommonParserSettings.headerExtractionEnabledistrue, irrespective of any user-provided headers inCommonSettings.getHeaders()protected java.lang.String[]parsedValuesStores the values parsed for a record.private AbstractParser<?>parserjava.util.Deque<java.lang.String[]>pendingRecordsprivate int[]selectedIndexesprotected CommonParserSettings<?>settingsprivate booleanskipEmptyLinesbooleantrim
-
Constructor Summary
Constructors Constructor Description ParserOutput(AbstractParser<?> parser, CommonParserSettings<?> settings)Initializes the ParserOutput with the configuration specified inCommonParserSettingsParserOutput(CommonParserSettings<?> settings)Initializes the ParserOutput with the configuration specified inCommonParserSettings
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddiscardValues()Discards the values parsed so farvoidemptyParsed()Adds a nullValue (as specified inCommonSettings.getNullValue()) to the output and prepares the next position in the record to receive more values.intgetCurrentColumn()Returns the position of the current parsed valuelonggetCurrentRecord()Returns the current record index.(package private) FieldSelectorgetFieldSelector()java.lang.String[]getHeaderAsStringArray()NormalizedString[]getHeaders()Returns the sequence of values that represent the headers each field in the input.int[]getSelectedIndexes()Returns the selected indexes of all fields as defined inCommonSettings.private voidinitializeColumnsToExtract(NormalizedString[] values)Initializes the sequence of selected fields, if any.protected voidinitializeHeaders()booleanisColumnReorderingEnabled()Indicates whether fields selected using the field selection methods (inCommonSettings) are being reordered.(package private) voidreset()Resets the parser output and prepares for a new parsing process.java.lang.String[]rowParsed()Gets all values parsed in theparsedValuesarrayvoidvalueParsed()Adds the accumulated value in the appender object to the output and prepares the next position in the record to receive more values.voidvalueParsed(java.lang.String value)Adds a value processed externally to the output and prepares the next position in the record to receive more values
-
-
-
Field Detail
-
column
protected int column
Keeps track of the current column being parsed in the input. Calls tovalueParsed()andemptyParsed()will increase the column count. This value is reset to zero after a row is parsed.
-
parsedValues
protected final java.lang.String[] parsedValues
Stores the values parsed for a record.
-
appenders
private final CharAppender[] appenders
Stores (shared) references to
CharAppenderfor each potential column (as given byCommonSettings.getMaxColumns()).Fields that are not selected will receive an instance of
NoopCharAppenderso all parser calls inAbstractParser.parseRecord()toappenderwill do nothing.Selected fields (given by
CommonParserSettings) will receive a functionalCharAppender.
-
settings
protected final CommonParserSettings<?> settings
-
skipEmptyLines
private final boolean skipEmptyLines
-
nullValue
private final java.lang.String nullValue
-
appender
public CharAppender appender
-
appenderInstance
private final CharAppender appenderInstance
-
columnsToExtractInitialized
private boolean columnsToExtractInitialized
-
columnsReordered
private boolean columnsReordered
-
columnReorderingEnabledSetting
private boolean columnReorderingEnabledSetting
-
headerStrings
private java.lang.String[] headerStrings
-
headers
private NormalizedString[] headers
-
selectedIndexes
private int[] selectedIndexes
-
currentRecord
private long currentRecord
-
trim
public boolean trim
-
pendingRecords
public final java.util.Deque<java.lang.String[]> pendingRecords
-
parsedHeaders
java.lang.String[] parsedHeaders
Headers parsed from the input whenCommonParserSettings.headerExtractionEnabledistrue, irrespective of any user-provided headers inCommonSettings.getHeaders()
-
parser
private final AbstractParser<?> parser
-
-
Constructor Detail
-
ParserOutput
public ParserOutput(CommonParserSettings<?> settings)
Initializes the ParserOutput with the configuration specified inCommonParserSettings- Parameters:
settings- the parser configuration
-
ParserOutput
public ParserOutput(AbstractParser<?> parser, CommonParserSettings<?> settings)
Initializes the ParserOutput with the configuration specified inCommonParserSettings- Parameters:
parser- the parser whose output will be managed by this class.settings- the parser configuration
-
-
Method Detail
-
initializeHeaders
protected void initializeHeaders()
-
rowParsed
public java.lang.String[] rowParsed()
Gets all values parsed in theparsedValuesarray- Returns:
- the sequence of parsed values in a record.
-
getFieldSelector
FieldSelector getFieldSelector()
-
initializeColumnsToExtract
private void initializeColumnsToExtract(NormalizedString[] values)
Initializes the sequence of selected fields, if any.- Parameters:
values- a sequence of values that represent the headers of the input. This can be either a parsed record or the headers as defined inCommonSettings.getHeaders()
-
getHeaderAsStringArray
public java.lang.String[] getHeaderAsStringArray()
-
getHeaders
public NormalizedString[] getHeaders()
Returns the sequence of values that represent the headers each field in the input. This can be either a parsed record or the headers as defined inCommonSettings.getHeaders()- Returns:
- the headers each field in the input
-
getSelectedIndexes
public int[] getSelectedIndexes()
Returns the selected indexes of all fields as defined inCommonSettings. Null if no fields were selected.- Returns:
- the selected indexes of all fields as defined in
CommonSettings. Null if no fields were selected.
-
isColumnReorderingEnabled
public boolean isColumnReorderingEnabled()
Indicates whether fields selected using the field selection methods (inCommonSettings) are being reordered.- Returns:
false if no fields were selected or column reordering has been disabled in
CommonParserSettings.isColumnReorderingEnabled()true if fields were selected and column reordering has been enabled in
CommonParserSettings.isColumnReorderingEnabled()
-
getCurrentColumn
public int getCurrentColumn()
Returns the position of the current parsed value- Returns:
- the position of the current parsed value
-
emptyParsed
public void emptyParsed()
Adds a nullValue (as specified inCommonSettings.getNullValue()) to the output and prepares the next position in the record to receive more values.
-
valueParsed
public void valueParsed()
Adds the accumulated value in the appender object to the output and prepares the next position in the record to receive more values.
-
valueParsed
public void valueParsed(java.lang.String value)
Adds a value processed externally to the output and prepares the next position in the record to receive more values- Parameters:
value- the value to be added to the current record position.
-
getCurrentRecord
public long getCurrentRecord()
Returns the current record index. The number returned here reflects the number of actually parsed and valid records sent to the output ofrowParsed().- Returns:
- the current record index.
-
discardValues
public final void discardValues()
Discards the values parsed so far
-
reset
final void reset()
Resets the parser output and prepares for a new parsing process.
-
-