Package com.univocity.parsers.common
Class ParserOutput
- java.lang.Object
-
- com.univocity.parsers.common.ParserOutput
-
public class ParserOutput extends java.lang.Object
The ParserOutput is the component that manages records parsed byAbstractParser
and 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
.- Author:
- uniVocity Software Pty Ltd - parsers@univocity.com
- See Also:
AbstractParser
,CommonSettings
- parsed records should be reordered according to the fields selected in
-
-
Field Summary
Fields Modifier and Type Field Description CharAppender
appender
The appender available to parsers for accumulating characters read from the input.protected int
column
Keeps track of the current column being parsed in the input.protected java.lang.String[]
parsedValues
Stores the values parsed for a record.protected CommonParserSettings<?>
settings
boolean
trim
-
Constructor Summary
Constructors Constructor Description ParserOutput(AbstractParser<?> parser, CommonParserSettings<?> settings)
Initializes the ParserOutput with the configuration specified inCommonParserSettings
ParserOutput(CommonParserSettings<?> settings)
Initializes the ParserOutput with the configuration specified inCommonParserSettings
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
discardValues()
Discards the values parsed so farvoid
emptyParsed()
Adds a nullValue (as specified inCommonSettings.getNullValue()
) to the output and prepares the next position in the record to receive more values.int
getCurrentColumn()
Returns the position of the current parsed valuelong
getCurrentRecord()
Returns the current record index.java.lang.String[]
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
.protected void
initializeHeaders()
boolean
isColumnReorderingEnabled()
Indicates whether fields selected using the field selection methods (inCommonSettings
) are being reordered.java.lang.String[]
rowParsed()
Gets all values parsed in theparsedValues
arrayvoid
valueParsed()
Adds the accumulated value in the appender object to the output and prepares the next position in the record to receive more values.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
-
-
-
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.
-
settings
protected final CommonParserSettings<?> settings
-
appender
public CharAppender appender
-
trim
public boolean trim
-
-
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 theparsedValues
array- Returns:
- the sequence of parsed values in a record.
-
getHeaders
public java.lang.String[] 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
-
-