Top Description Fields Constructors Methods
com.univocity.parsers.common

public abstract Class AbstractParser<T extends CommonParserSettings<?>>

extends Object
Class Inheritance
Known Direct Subclasses
com.univocity.parsers.csv.CsvParser, com.univocity.parsers.fixed.FixedWidthParser, com.univocity.parsers.tsv.TsvParser
Type Parameters
<T>
The specific parser settings configuration class, which can potentially provide additional configuration options supported by the parser implementation.
Imports
com.univocity.parsers.common.input.EOFException, com.univocity.parsers.common.input.*, com.univocity.parsers.common.iterators.*, com.univocity.parsers.common.processor.*, com.univocity.parsers.common.processor.core.*, com.univocity.parsers.common.record.*, java.io.*, java.nio.charset.*, java.util.*

The AbstractParser class provides a common ground for all parsers in univocity-parsers.

It handles all settings defined by CommonParserSettings, and delegates the parsing algorithm implementation to its subclasses through the abstract method AbstractParser#parseRecord()

The following (absolutely required) attributes are exposed to subclasses:

Author
Univocity Software Pty Ltd - [email protected]
See Also
com.univocity.parsers.csv.CsvParser, com.univocity.parsers.csv.CsvParserSettings, com.univocity.parsers.fixed.FixedWidthParser, com.univocity.parsers.fixed.FixedWidthParserSettings, com.univocity.parsers.common.input.CharInputReader, com.univocity.parsers.common.ParserOutput

Field Summary

Modifier and TypeField and Description
protected char
private final boolean
protected final char
protected final Map<Long, String>
protected ParsingContext
private final int
private final ProcessorErrorHandler<T extends Context>
private final boolean
private boolean
protected boolean
protected boolean
protected CharInputReader
protected String
private final LineReader
protected final ParserOutput
private final boolean
protected Processor<T extends Context>
private final long
private final long
protected final T
protected final int

Constructor Summary

AccessConstructor and Description
public
AbstractParser(T
the parser configuration
settings
)

All parsers must support, at the very least, the settings provided by CommonParserSettings.

Method Summary

Modifier and TypeMethod and Description
private <T> List<T>
beginParseAll(boolean validateReader, Reader reader, int expectedRowCount)

public final void
beginParsing(Reader
The input to be parsed.
reader
)

Starts an iterator-style parsing cycle.

public final void
beginParsing(File
The file to be parsed.
file
)

Starts an iterator-style parsing cycle.

public final void
beginParsing(File
The file to be parsed.
file
,
String
the encoding of the file
encoding
)

Starts an iterator-style parsing cycle.

public final void
beginParsing(File
The file to be parsed.
file
,
Charset
the encoding of the file
encoding
)

Starts an iterator-style parsing cycle.

public final void
beginParsing(InputStream
The input to be parsed. The input stream will be closed automatically in case of errors unless CommonParserSettings#isAutoClosingEnabled() evaluates to false.
input
)

Starts an iterator-style parsing cycle.

public final void
beginParsing(InputStream
The input to be parsed. The input stream will be closed automatically in case of errors unless CommonParserSettings#isAutoClosingEnabled() evaluates to false.
input
,
String
the encoding of the input stream
encoding
)

Starts an iterator-style parsing cycle.

public final void
beginParsing(InputStream
The input to be parsed. The input stream will be closed automatically in case of errors unless CommonParserSettings#isAutoClosingEnabled() evaluates to false.
input
,
Charset
the encoding of the input stream
encoding
)

Starts an iterator-style parsing cycle.

protected boolean

Returns:

a flag indicating whether the parser was processing a value when the end of the input was reached.
consumeValueOnEOF
()

Allows the parser implementation to handle any value that was being consumed when the end of the input was reached

protected ParsingContext
pack-priv void
pack-priv final Map<Long, String>

Returns:

a map containing the line numbers and comments found in each.
getComments
()

Returns all comments collected by the parser so far.

public final ParsingContext

Returns:

the parsing context
getContext
()

Returns the current parsing context with information about the status of the parser at any given time.

protected InputAnalysisProcess

Returns:

a custom implementation of InputAnalysisProcess. By default, null is returned and no special input analysis will be performed.
getInputAnalysisProcess
()

Allows the parser implementation to traverse the input buffer before the parsing process starts, in order to enable automatic configuration and discovery of data formats.

pack-priv final String

Returns:

the last comment found in the input.
getLastComment
()

Returns the last comment found in the input.

private String
pack-priv final String[]

Returns:

the headers parsed from the input, when CommonParserSettings#headerExtractionEnabled is true.
getParsedHeaders
()

Returns the headers parsed from the input, if and only if CommonParserSettings#headerExtractionEnabled is true.

public final RecordMetaData

Returns:

the metadata of com.univocity.parsers.common.record.Records generated with the current input.
getRecordMetadata
()

Returns the metadata associated with com.univocity.parsers.common.record.Records parsed from the input using AbstractParser#parseAllRecords(File) or AbstractParser#parseNextRecord().

private String[]
private TextParsingException
protected boolean
protected void
private final List<String[]>
internalParseAll(boolean validateReader, Reader reader, int expectedRowCount)

private List<Record>
internalParseAllRecords(boolean validateReader, Reader reader, int expectedRowCount)

public final IterableResult<String[], ParsingContext>

Returns:

an iterator for rows parsed from the input.
iterate
(final File
the input File
input
,
String
the encoding of the input File
encoding
)

Provides an IterableResult for iterating rows parsed from the input.

public final IterableResult<String[], ParsingContext>

Returns:

an iterator for rows parsed from the input.
iterate
(final File
the input File
input
,
final Charset
the encoding of the input File
encoding
)

Provides an IterableResult for iterating rows parsed from the input.

public final IterableResult<String[], ParsingContext>

Returns:

an iterator for rows parsed from the input.
iterate
(final File
the input File
input
)

Provides an IterableResult for iterating rows parsed from the input.

public final IterableResult<String[], ParsingContext>

Returns:

an iterable over the results of parsing the Reader
iterate
(final Reader
the input Reader
input
)

Provides an IterableResult for iterating rows parsed from the input.

public final IterableResult<String[], ParsingContext>

Returns:

an iterator for rows parsed from the input.
iterate
(final InputStream
the the InputStream with contents to be parsed
input
,
String
the character encoding to be used for processing the given input.
encoding
)

Provides an IterableResult for iterating rows parsed from the input.

public final IterableResult<String[], ParsingContext>

Returns:

an iterator for rows parsed from the input.
iterate
(final InputStream
the the InputStream with contents to be parsed
input
,
final Charset
the character encoding to be used for processing the given input.
encoding
)

Provides an IterableResult for iterating rows parsed from the input.

public final IterableResult<String[], ParsingContext>

Returns:

an iterator for rows parsed from the input.
iterate
(final InputStream
the the InputStream with contents to be parsed
input
)

Provides an IterableResult for iterating rows parsed from the input.

public final IterableResult<Record, ParsingContext>

Returns:

an iterator for records parsed from the input.
iterateRecords
(final File
the input File
input
,
String
the encoding of the input File
encoding
)

Provides an IterableResult for iterating records parsed from the input.

public final IterableResult<Record, ParsingContext>

Returns:

an iterator for records parsed from the input.
iterateRecords
(final File
the input File
input
,
final Charset
the encoding of the input File
encoding
)

Provides an IterableResult for iterating records parsed from the input.

public final IterableResult<Record, ParsingContext>

Returns:

an iterator for records parsed from the input.
iterateRecords
(final File
the input File
input
)

Provides an IterableResult for iterating records parsed from the input.

public final IterableResult<Record, ParsingContext>

Returns:

an iterator for records parsed from the input.
iterateRecords
(final Reader
the input Reader
input
)

Provides an IterableResult for iterating records parsed from the input.

public final IterableResult<Record, ParsingContext>

Returns:

an iterator for records parsed from the input.
iterateRecords
(final InputStream
the the InputStream with contents to be parsed
input
,
String
the character encoding to be used for processing the given input.
encoding
)

Provides an IterableResult for iterating records parsed from the input.

public final IterableResult<Record, ParsingContext>

Returns:

an iterator for records parsed from the input.
iterateRecords
(final InputStream
the the InputStream with contents to be parsed
input
,
final Charset
the character encoding to be used for processing the given input.
encoding
)

Provides an IterableResult for iterating records parsed from the input.

public final IterableResult<Record, ParsingContext>

Returns:

an iterator for records parsed from the input.
iterateRecords
(final InputStream
the the InputStream with contents to be parsed
input
)

Provides an IterableResult for iterating records parsed from the input.

public final void
parse(Reader
The input to be parsed.
reader
)

Parses the entirety of a given input and delegates each parsed row to an instance of RowProcessor, defined by CommonParserSettings#getRowProcessor().

public final void
parse(File
The file to be parsed.
file
)

Parses the entirety of a given file and delegates each parsed row to an instance of RowProcessor, defined by CommonParserSettings#getRowProcessor().

public final void
parse(File
The file to be parsed.
file
,
String
the encoding of the file
encoding
)

Parses the entirety of a given file and delegates each parsed row to an instance of RowProcessor, defined by CommonParserSettings#getRowProcessor().

public final void
parse(File
The file to be parsed.
file
,
Charset
the encoding of the file
encoding
)

Parses the entirety of a given file and delegates each parsed row to an instance of RowProcessor, defined by CommonParserSettings#getRowProcessor().

public final void
parse(InputStream
The input to be parsed. The input stream will be closed automatically, unless CommonParserSettings#isAutoClosingEnabled() evaluates to false.
input
)

Parses the entirety of a given input and delegates each parsed row to an instance of RowProcessor, defined by CommonParserSettings#getRowProcessor().

public final void
parse(InputStream
The input to be parsed. The input stream will be closed automatically, unless CommonParserSettings#isAutoClosingEnabled() evaluates to false.
input
,
String
the encoding of the input stream
encoding
)

Parses the entirety of a given input and delegates each parsed row to an instance of RowProcessor, defined by CommonParserSettings#getRowProcessor().

public final void
parse(InputStream
The input to be parsed. The input stream will be closed automatically, unless CommonParserSettings#isAutoClosingEnabled() evaluates to false.
input
,
Charset
the encoding of the input stream
encoding
)

Parses the entirety of a given input and delegates each parsed row to an instance of RowProcessor, defined by CommonParserSettings#getRowProcessor().

public List<String[]>

Returns:

the list of all remaining records parsed from the input.
parseAll
(int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all remaining rows from the input and returns them in a list.

public List<String[]>

Returns:

the list of all remaining records parsed from the input.
parseAll
()

Parses all remaining rows from the input and returns them in a list.

public final List<String[]>

Returns:

the list of all records parsed from the input.
parseAll
(Reader
the input to be parsed
reader
)

Parses all records from the input and returns them in a list.

public final List<String[]>

Returns:

the list of all records parsed from the input.
parseAll
(Reader
the input to be parsed
reader
,
int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all records from the input and returns them in a list.

public final List<String[]>

Returns:

the list of all records parsed from the file.
parseAll
(File
the input file to be parsed
file
,
int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all records from a file and returns them in a list.

public final List<String[]>

Returns:

the list of all records parsed from the file.
parseAll
(File
the input file to be parsed
file
,
String
the encoding of the file
encoding
,
int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all records from a file and returns them in a list.

public final List<String[]>

Returns:

the list of all records parsed from the file.
parseAll
(File
the input file to be parsed
file
,
Charset
the encoding of the file
encoding
,
int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all records from a file and returns them in a list.

public final List<String[]>

Returns:

the list of all records parsed from the input.
parseAll
(InputStream
the input stream to be parsed. The input stream will be closed automatically unless CommonParserSettings#isAutoClosingEnabled() evaluates to false
input
,
int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all records from an input stream and returns them in a list.

public final List<String[]>

Returns:

the list of all records parsed from the input.
parseAll
(InputStream
the input stream to be parsed. The input stream will be closed automatically unless CommonParserSettings#isAutoClosingEnabled() evaluates to false
input
,
String
the encoding of the input stream
encoding
,
int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all records from an input stream and returns them in a list.

public final List<String[]>

Returns:

the list of all records parsed from the input.
parseAll
(InputStream
the input stream to be parsed. The input stream will be closed automatically unless CommonParserSettings#isAutoClosingEnabled() evaluates to false
input
,
Charset
the encoding of the input stream
encoding
,
int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all records from an input stream and returns them in a list.

public final List<String[]>

Returns:

the list of all records parsed from the file.
parseAll
(File
the input file to be parsed
file
)

Parses all records from a file and returns them in a list.

public final List<String[]>

Returns:

the list of all records parsed from the file.
parseAll
(File
the input file to be parsed
file
,
String
the encoding of the file
encoding
)

Parses all records from a file and returns them in a list.

public final List<String[]>

Returns:

the list of all records parsed from the file.
parseAll
(File
the input file to be parsed
file
,
Charset
the encoding of the file
encoding
)

Parses all records from a file and returns them in a list.

public final List<String[]>

Returns:

the list of all records parsed from the input.
parseAll
(InputStream
the input stream to be parsed. The input stream will be closed automatically unless CommonParserSettings#isAutoClosingEnabled() evaluates to false
input
)

Parses all records from an input stream and returns them in a list.

public final List<String[]>

Returns:

the list of all records parsed from the input.
parseAll
(InputStream
the input stream to be parsed. The input stream will be closed automatically unless CommonParserSettings#isAutoClosingEnabled() evaluates to false
input
,
String
the encoding of the input stream
encoding
)

Parses all records from an input stream and returns them in a list.

public final List<String[]>

Returns:

the list of all records parsed from the input.
parseAll
(InputStream
the input stream to be parsed. The input stream will be closed automatically unless CommonParserSettings#isAutoClosingEnabled() evaluates to false
input
,
Charset
the encoding of the input stream
encoding
)

Parses all records from an input stream and returns them in a list.

public List<Record>

Returns:

the list of all remaining records parsed from the input.
parseAllRecords
(int
expected number of com.univocity.parsers.common.record.Records to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all remaining com.univocity.parsers.common.record.Records from the input and returns them in a list.

public List<Record>

Returns:

the list of all remaining com.univocity.parsers.common.record.Records parsed from the input.
parseAllRecords
()

Parses all remaining com.univocity.parsers.common.record.Records from the input and returns them in a list.

public final List<Record>

Returns:

the list of all records parsed from the file.
parseAllRecords
(File
the input file to be parsed
file
,
int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all records from a file and returns them in a list.

public final List<Record>

Returns:

the list of all records parsed from the file.
parseAllRecords
(File
the input file to be parsed
file
,
String
the encoding of the file
encoding
,
int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all records from a file and returns them in a list.

public final List<Record>

Returns:

the list of all records parsed from the file.
parseAllRecords
(File
the input file to be parsed
file
,
Charset
the encoding of the file
encoding
,
int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all records from a file and returns them in a list.

public final List<Record>

Returns:

the list of all records parsed from the input.
parseAllRecords
(InputStream
the input stream to be parsed. The input stream will be closed automatically unless CommonParserSettings#isAutoClosingEnabled() evaluates to false
input
,
int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all records from an input stream and returns them in a list.

public final List<Record>

Returns:

the list of all records parsed from the input.
parseAllRecords
(InputStream
the input stream to be parsed. The input stream will be closed automatically unless CommonParserSettings#isAutoClosingEnabled() evaluates to false
input
,
String
the encoding of the input stream
encoding
,
int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all records from an input stream and returns them in a list.

public final List<Record>

Returns:

the list of all records parsed from the input.
parseAllRecords
(InputStream
the input stream to be parsed. The input stream will be closed automatically unless CommonParserSettings#isAutoClosingEnabled() evaluates to false
input
,
Charset
the encoding of the input stream
encoding
,
int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all records from an input stream and returns them in a list.

public final List<Record>

Returns:

the list of all records parsed from the file.
parseAllRecords
(File
the input file to be parsed
file
)

Parses all records from a file and returns them in a list.

public final List<Record>

Returns:

the list of all records parsed from the file.
parseAllRecords
(File
the input file to be parsed
file
,
String
the encoding of the file
encoding
)

Parses all records from a file and returns them in a list.

public final List<Record>

Returns:

the list of all records parsed from the file.
parseAllRecords
(File
the input file to be parsed
file
,
Charset
the encoding of the file
encoding
)

Parses all records from a file and returns them in a list.

public final List<Record>

Returns:

the list of all records parsed from the input.
parseAllRecords
(InputStream
the input stream to be parsed. The input stream will be closed automatically unless CommonParserSettings#isAutoClosingEnabled() evaluates to false
input
)

Parses all records from an input stream and returns them in a list.

public final List<Record>

Returns:

the list of all records parsed from the input.
parseAllRecords
(InputStream
the input stream to be parsed. The input stream will be closed automatically unless CommonParserSettings#isAutoClosingEnabled() evaluates to false
input
,
String
the encoding of the input stream
encoding
)

Parses all records from an input stream and returns them in a list.

public final List<Record>

Returns:

the list of all records parsed from the input.
parseAllRecords
(InputStream
the input stream to be parsed. The input stream will be closed automatically unless CommonParserSettings#isAutoClosingEnabled() evaluates to false
input
,
Charset
the encoding of the input stream
encoding
)

Parses all records from an input stream and returns them in a list.

public final List<Record>

Returns:

the list of all records parsed from the input.
parseAllRecords
(Reader
the input to be parsed
reader
,
int
expected number of rows to be parsed from the input. Used to pre-allocate the size of the output List
expectedRowCount
)

Parses all records from the input and returns them in a list.

public final List<Record>

Returns:

the list of all records parsed from the input.
parseAllRecords
(Reader
the input to be parsed
reader
)

Parses all records from the input and returns them in a list.

public final String[]

Returns:

the values parsed from the input line
parseLine
(String
a line of text to be parsed
line
)

Parses a single line from a String in the format supported by the parser implementation.

public final String[]

Returns:

The record parsed from the input or null if there's no more characters to read.
parseNext
()

Parses the next record from the input.

public final Record

Returns:

The record parsed from the input or null if there's no more characters to read.
parseNextRecord
()

Parses the next record from the input.

protected abstract void
parseRecord()

Parser-specific implementation for reading a single record from the input.

public final Record

Returns:

the com.univocity.parsers.common.record.Record containing the values parsed from the input line
parseRecord
(String
a line of text to be parsed
line
)

Parses a single line from a String in the format supported by the parser implementation.

protected void
protected final void
reloadHeaders()

Reloads headers from settings.

private void
private void
stopParsing(Throwable error)

In case of errors, stops parsing and closes all open resources.

public final void
stopParsing()

Stops parsing and closes all open resources.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait