Class AbstractParser<T extends CommonParserSettings<?>>
- java.lang.Object
-
- com.univocity.parsers.common.AbstractParser<T>
-
- Type Parameters:
T
- The specific parser settings configuration class, which can potentially provide additional configuration options supported by the parser implementation.
- Direct Known Subclasses:
CsvParser
,FixedWidthParser
,TsvParser
public abstract class AbstractParser<T extends CommonParserSettings<?>> extends java.lang.Object
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 methodparseRecord()
The following (absolutely required) attributes are exposed to subclasses:
- input (
CharInputReader
): the character input provider that reads characters from a given input into an internal buffer - output (
ParserOutput
): the output handler for every record parsed from the input. Implementors must use this object to handle the input (such as appending characters and notifying of values parsed) - ch (char): the current character read from the input
-
-
Field Summary
Fields Modifier and Type Field Description protected char
ch
private boolean
collectComments
protected char
comment
protected java.util.Map<java.lang.Long,java.lang.String>
comments
protected ParsingContext
context
private int
errorContentLength
private ProcessorErrorHandler
errorHandler
private boolean
extractHeaders
private boolean
extractingHeaders
protected boolean
ignoreLeadingWhitespace
protected boolean
ignoreTrailingWhitespace
protected CharInputReader
input
protected java.lang.String
lastComment
private LineReader
lineReader
protected ParserOutput
output
private boolean
processComments
protected Processor
processor
private long
recordsToRead
private long
rowsToSkip
protected T
settings
protected int
whitespaceRangeStart
-
Constructor Summary
Constructors Constructor Description AbstractParser(T settings)
All parsers must support, at the very least, the settings provided byCommonParserSettings
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private <T> java.util.List<T>
beginParseAll(boolean validateReader, java.io.Reader reader, int expectedRowCount)
void
beginParsing(java.io.File file)
Starts an iterator-style parsing cycle.void
beginParsing(java.io.File file, java.lang.String encoding)
Starts an iterator-style parsing cycle.void
beginParsing(java.io.File file, java.nio.charset.Charset encoding)
Starts an iterator-style parsing cycle.void
beginParsing(java.io.InputStream input)
Starts an iterator-style parsing cycle.void
beginParsing(java.io.InputStream input, java.lang.String encoding)
Starts an iterator-style parsing cycle.void
beginParsing(java.io.InputStream input, java.nio.charset.Charset encoding)
Starts an iterator-style parsing cycle.void
beginParsing(java.io.Reader reader)
Starts an iterator-style parsing cycle.protected boolean
consumeValueOnEOF()
Allows the parser implementation to handle any value that was being consumed when the end of the input was reachedprotected ParsingContext
createParsingContext()
(package private) void
extractHeadersIfRequired()
(package private) java.util.Map<java.lang.Long,java.lang.String>
getComments()
Returns all comments collected by the parser so far.ParsingContext
getContext()
Returns the current parsing context with information about the status of the parser at any given time.protected InputAnalysisProcess
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.(package private) java.lang.String
getLastComment()
Returns the last comment found in the input.private java.lang.String
getParsedContent(java.lang.CharSequence tmp)
(package private) java.lang.String[]
getParsedHeaders()
Returns the headers parsed from the input, if and only ifCommonParserSettings.headerExtractionEnabled
istrue
.RecordMetaData
getRecordMetadata()
Returns the metadata associated withRecord
s parsed from the input usingparseAllRecords(File)
orparseNextRecord()
.private java.lang.String[]
handleEOF()
private TextParsingException
handleException(java.lang.Throwable ex)
protected boolean
inComment()
protected void
initialize()
private java.util.List<java.lang.String[]>
internalParseAll(boolean validateReader, java.io.Reader reader, int expectedRowCount)
private java.util.List<Record>
internalParseAllRecords(boolean validateReader, java.io.Reader reader, int expectedRowCount)
IterableResult<java.lang.String[],ParsingContext>
iterate(java.io.File input)
Provides anIterableResult
for iterating rows parsed from the input.IterableResult<java.lang.String[],ParsingContext>
iterate(java.io.File input, java.lang.String encoding)
Provides anIterableResult
for iterating rows parsed from the input.IterableResult<java.lang.String[],ParsingContext>
iterate(java.io.File input, java.nio.charset.Charset encoding)
Provides anIterableResult
for iterating rows parsed from the input.IterableResult<java.lang.String[],ParsingContext>
iterate(java.io.InputStream input)
Provides anIterableResult
for iterating rows parsed from the input.IterableResult<java.lang.String[],ParsingContext>
iterate(java.io.InputStream input, java.lang.String encoding)
Provides anIterableResult
for iterating rows parsed from the input.IterableResult<java.lang.String[],ParsingContext>
iterate(java.io.InputStream input, java.nio.charset.Charset encoding)
Provides anIterableResult
for iterating rows parsed from the input.IterableResult<java.lang.String[],ParsingContext>
iterate(java.io.Reader input)
Provides anIterableResult
for iterating rows parsed from the input.IterableResult<Record,ParsingContext>
iterateRecords(java.io.File input)
Provides anIterableResult
for iterating records parsed from the input.IterableResult<Record,ParsingContext>
iterateRecords(java.io.File input, java.lang.String encoding)
Provides anIterableResult
for iterating records parsed from the input.IterableResult<Record,ParsingContext>
iterateRecords(java.io.File input, java.nio.charset.Charset encoding)
Provides anIterableResult
for iterating records parsed from the input.IterableResult<Record,ParsingContext>
iterateRecords(java.io.InputStream input)
Provides anIterableResult
for iterating records parsed from the input.IterableResult<Record,ParsingContext>
iterateRecords(java.io.InputStream input, java.lang.String encoding)
Provides anIterableResult
for iterating records parsed from the input.IterableResult<Record,ParsingContext>
iterateRecords(java.io.InputStream input, java.nio.charset.Charset encoding)
Provides anIterableResult
for iterating records parsed from the input.IterableResult<Record,ParsingContext>
iterateRecords(java.io.Reader input)
Provides anIterableResult
for iterating records parsed from the input.void
parse(java.io.File file)
Parses the entirety of a given file and delegates each parsed row to an instance ofRowProcessor
, defined byCommonParserSettings.getRowProcessor()
.void
parse(java.io.File file, java.lang.String encoding)
Parses the entirety of a given file and delegates each parsed row to an instance ofRowProcessor
, defined byCommonParserSettings.getRowProcessor()
.void
parse(java.io.File file, java.nio.charset.Charset encoding)
Parses the entirety of a given file and delegates each parsed row to an instance ofRowProcessor
, defined byCommonParserSettings.getRowProcessor()
.void
parse(java.io.InputStream input)
Parses the entirety of a given input and delegates each parsed row to an instance ofRowProcessor
, defined byCommonParserSettings.getRowProcessor()
.void
parse(java.io.InputStream input, java.lang.String encoding)
Parses the entirety of a given input and delegates each parsed row to an instance ofRowProcessor
, defined byCommonParserSettings.getRowProcessor()
.void
parse(java.io.InputStream input, java.nio.charset.Charset encoding)
Parses the entirety of a given input and delegates each parsed row to an instance ofRowProcessor
, defined byCommonParserSettings.getRowProcessor()
.void
parse(java.io.Reader reader)
Parses the entirety of a given input and delegates each parsed row to an instance ofRowProcessor
, defined byCommonParserSettings.getRowProcessor()
.java.util.List<java.lang.String[]>
parseAll()
Parses all remaining rows from the input and returns them in a list.java.util.List<java.lang.String[]>
parseAll(int expectedRowCount)
Parses all remaining rows from the input and returns them in a list.java.util.List<java.lang.String[]>
parseAll(java.io.File file)
Parses all records from a file and returns them in a list.java.util.List<java.lang.String[]>
parseAll(java.io.File file, int expectedRowCount)
Parses all records from a file and returns them in a list.java.util.List<java.lang.String[]>
parseAll(java.io.File file, java.lang.String encoding)
Parses all records from a file and returns them in a list.java.util.List<java.lang.String[]>
parseAll(java.io.File file, java.lang.String encoding, int expectedRowCount)
Parses all records from a file and returns them in a list.java.util.List<java.lang.String[]>
parseAll(java.io.File file, java.nio.charset.Charset encoding)
Parses all records from a file and returns them in a list.java.util.List<java.lang.String[]>
parseAll(java.io.File file, java.nio.charset.Charset encoding, int expectedRowCount)
Parses all records from a file and returns them in a list.java.util.List<java.lang.String[]>
parseAll(java.io.InputStream input)
Parses all records from an input stream and returns them in a list.java.util.List<java.lang.String[]>
parseAll(java.io.InputStream input, int expectedRowCount)
Parses all records from an input stream and returns them in a list.java.util.List<java.lang.String[]>
parseAll(java.io.InputStream input, java.lang.String encoding)
Parses all records from an input stream and returns them in a list.java.util.List<java.lang.String[]>
parseAll(java.io.InputStream input, java.lang.String encoding, int expectedRowCount)
Parses all records from an input stream and returns them in a list.java.util.List<java.lang.String[]>
parseAll(java.io.InputStream input, java.nio.charset.Charset encoding)
Parses all records from an input stream and returns them in a list.java.util.List<java.lang.String[]>
parseAll(java.io.InputStream input, java.nio.charset.Charset encoding, int expectedRowCount)
Parses all records from an input stream and returns them in a list.java.util.List<java.lang.String[]>
parseAll(java.io.Reader reader)
Parses all records from the input and returns them in a list.java.util.List<java.lang.String[]>
parseAll(java.io.Reader reader, int expectedRowCount)
Parses all records from the input and returns them in a list.java.util.List<Record>
parseAllRecords()
Parses all remainingRecord
s from the input and returns them in a list.java.util.List<Record>
parseAllRecords(int expectedRowCount)
Parses all remainingRecord
s from the input and returns them in a list.java.util.List<Record>
parseAllRecords(java.io.File file)
Parses all records from a file and returns them in a list.java.util.List<Record>
parseAllRecords(java.io.File file, int expectedRowCount)
Parses all records from a file and returns them in a list.java.util.List<Record>
parseAllRecords(java.io.File file, java.lang.String encoding)
Parses all records from a file and returns them in a list.java.util.List<Record>
parseAllRecords(java.io.File file, java.lang.String encoding, int expectedRowCount)
Parses all records from a file and returns them in a list.java.util.List<Record>
parseAllRecords(java.io.File file, java.nio.charset.Charset encoding)
Parses all records from a file and returns them in a list.java.util.List<Record>
parseAllRecords(java.io.File file, java.nio.charset.Charset encoding, int expectedRowCount)
Parses all records from a file and returns them in a list.java.util.List<Record>
parseAllRecords(java.io.InputStream input)
Parses all records from an input stream and returns them in a list.java.util.List<Record>
parseAllRecords(java.io.InputStream input, int expectedRowCount)
Parses all records from an input stream and returns them in a list.java.util.List<Record>
parseAllRecords(java.io.InputStream input, java.lang.String encoding)
Parses all records from an input stream and returns them in a list.java.util.List<Record>
parseAllRecords(java.io.InputStream input, java.lang.String encoding, int expectedRowCount)
Parses all records from an input stream and returns them in a list.java.util.List<Record>
parseAllRecords(java.io.InputStream input, java.nio.charset.Charset encoding)
Parses all records from an input stream and returns them in a list.java.util.List<Record>
parseAllRecords(java.io.InputStream input, java.nio.charset.Charset encoding, int expectedRowCount)
Parses all records from an input stream and returns them in a list.java.util.List<Record>
parseAllRecords(java.io.Reader reader)
Parses all records from the input and returns them in a list.java.util.List<Record>
parseAllRecords(java.io.Reader reader, int expectedRowCount)
Parses all records from the input and returns them in a list.java.lang.String[]
parseLine(java.lang.String line)
Parses a single line from a String in the format supported by the parser implementation.java.lang.String[]
parseNext()
Parses the next record from the input.Record
parseNextRecord()
Parses the next record from the input.protected abstract void
parseRecord()
Parser-specific implementation for reading a single record from the input.Record
parseRecord(java.lang.String line)
Parses a single line from a String in the format supported by the parser implementation.protected void
processComment()
protected void
reloadHeaders()
Reloads headers from settings.private void
rowProcessed(java.lang.String[] row)
void
stopParsing()
Stops parsing and closes all open resources.private void
stopParsing(java.lang.Throwable error)
In case of errors, stops parsing and closes all open resources.
-
-
-
Field Detail
-
settings
protected final T extends CommonParserSettings<?> settings
-
output
protected final ParserOutput output
-
recordsToRead
private final long recordsToRead
-
comment
protected final char comment
-
lineReader
private final LineReader lineReader
-
context
protected ParsingContext context
-
processor
protected Processor processor
-
input
protected CharInputReader input
-
ch
protected char ch
-
errorHandler
private final ProcessorErrorHandler errorHandler
-
rowsToSkip
private final long rowsToSkip
-
comments
protected final java.util.Map<java.lang.Long,java.lang.String> comments
-
lastComment
protected java.lang.String lastComment
-
collectComments
private final boolean collectComments
-
errorContentLength
private final int errorContentLength
-
extractingHeaders
private boolean extractingHeaders
-
extractHeaders
private final boolean extractHeaders
-
whitespaceRangeStart
protected final int whitespaceRangeStart
-
ignoreTrailingWhitespace
protected boolean ignoreTrailingWhitespace
-
ignoreLeadingWhitespace
protected boolean ignoreLeadingWhitespace
-
processComments
private final boolean processComments
-
-
Constructor Detail
-
AbstractParser
public AbstractParser(T settings)
All parsers must support, at the very least, the settings provided byCommonParserSettings
. The AbstractParser requires its configuration to be properly initialized.- Parameters:
settings
- the parser configuration
-
-
Method Detail
-
processComment
protected void processComment()
-
parse
public final void parse(java.io.Reader reader)
Parses the entirety of a given input and delegates each parsed row to an instance ofRowProcessor
, defined byCommonParserSettings.getRowProcessor()
.- Parameters:
reader
- The input to be parsed.
-
parseRecord
protected abstract void parseRecord()
Parser-specific implementation for reading a single record from the input.The AbstractParser handles the initialization and processing of the input until it is ready to be parsed.
It then delegates the input to the parser-specific implementation defined by
parseRecord()
. In general, an implementation ofparseRecord()
will perform the following steps:- Test the character stored in ch and take some action on it (e.g. is while (ch != '\n'){doSomething()})
- Request more characters by calling ch = input.nextChar();
- Append the desired characters to the output by executing, for example, output.appender.append(ch)
- Notify a value of the record has been fully read by executing output.valueParsed(). This will clear the output appender (
CharAppender
) so the next call to output.appender.append(ch) will be store the character of the next parsed value - Rinse and repeat until all values of the record are parsed
Once the
parseRecord()
returns, the AbstractParser takes over and handles the information (generally, reorganizing it and passing it on to aRowProcessor
).After the record processing, the AbstractParser reads the next characters from the input, delegating control again to the parseRecord() implementation for processing of the next record.
This cycle repeats until the reading process is stopped by the user, the input is exhausted, or an error happens.
In case of errors, the unchecked exception
TextParsingException
will be thrown and all resources in use will be closed automatically unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
. The exception should contain the cause and more information about where in the input the error happened.- See Also:
CharInputReader
,CharAppender
,ParserOutput
,TextParsingException
,RowProcessor
-
consumeValueOnEOF
protected boolean consumeValueOnEOF()
Allows the parser implementation to handle any value that was being consumed when the end of the input was reached- Returns:
- a flag indicating whether the parser was processing a value when the end of the input was reached.
-
handleEOF
private java.lang.String[] handleEOF()
-
beginParsing
public final void beginParsing(java.io.Reader reader)
Starts an iterator-style parsing cycle. If aRowProcessor
is provided in the configuration, it will be used to perform additional processing. The parsed records must be read one by one with the invocation ofparseNext()
. The user may invoke @linkstopParsing()
to stop reading from the input.- Parameters:
reader
- The input to be parsed.
-
extractHeadersIfRequired
void extractHeadersIfRequired()
-
createParsingContext
protected ParsingContext createParsingContext()
-
initialize
protected void initialize()
-
getInputAnalysisProcess
protected InputAnalysisProcess 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.- Returns:
- a custom implementation of
InputAnalysisProcess
. By default,null
is returned and no special input analysis will be performed.
-
getParsedContent
private java.lang.String getParsedContent(java.lang.CharSequence tmp)
-
handleException
private TextParsingException handleException(java.lang.Throwable ex)
-
stopParsing
private void stopParsing(java.lang.Throwable error)
In case of errors, stops parsing and closes all open resources. Avoids hiding the original exception in case another error occurs when stopping.
-
stopParsing
public final void stopParsing()
Stops parsing and closes all open resources.
-
beginParseAll
private <T> java.util.List<T> beginParseAll(boolean validateReader, java.io.Reader reader, int expectedRowCount)
-
parseAll
public java.util.List<java.lang.String[]> parseAll(int expectedRowCount)
Parses all remaining rows from the input and returns them in a list.- Parameters:
expectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all remaining records parsed from the input.
-
parseAll
public java.util.List<java.lang.String[]> parseAll()
Parses all remaining rows from the input and returns them in a list.- Returns:
- the list of all remaining records parsed from the input.
-
parseAllRecords
public java.util.List<Record> parseAllRecords(int expectedRowCount)
Parses all remainingRecord
s from the input and returns them in a list.- Parameters:
expectedRowCount
- expected number ofRecord
s to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all remaining records parsed from the input.
-
parseAllRecords
public java.util.List<Record> parseAllRecords()
Parses all remainingRecord
s from the input and returns them in a list.- Returns:
- the list of all remaining
Record
s parsed from the input.
-
parseAll
public final java.util.List<java.lang.String[]> parseAll(java.io.Reader reader)
Parses all records from the input and returns them in a list.- Parameters:
reader
- the input to be parsed- Returns:
- the list of all records parsed from the input.
-
parseAll
public final java.util.List<java.lang.String[]> parseAll(java.io.Reader reader, int expectedRowCount)
Parses all records from the input and returns them in a list.- Parameters:
reader
- the input to be parsedexpectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all records parsed from the input.
-
internalParseAll
private final java.util.List<java.lang.String[]> internalParseAll(boolean validateReader, java.io.Reader reader, int expectedRowCount)
-
inComment
protected boolean inComment()
-
parseNext
public final java.lang.String[] parseNext()
Parses the next record from the input. Note thatbeginParsing(Reader)
must have been invoked once before calling this method. If the end of the input is reached, then this method will return null. Additionally, all resources will be closed automatically at the end of the input or if any error happens while parsing, unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
.- Returns:
- The record parsed from the input or null if there's no more characters to read.
-
reloadHeaders
protected final void reloadHeaders()
Reloads headers from settings.
-
parseRecord
public final Record parseRecord(java.lang.String line)
Parses a single line from a String in the format supported by the parser implementation.- Parameters:
line
- a line of text to be parsed- Returns:
- the
Record
containing the values parsed from the input line
-
parseLine
public final java.lang.String[] parseLine(java.lang.String line)
Parses a single line from a String in the format supported by the parser implementation.- Parameters:
line
- a line of text to be parsed- Returns:
- the values parsed from the input line
-
rowProcessed
private void rowProcessed(java.lang.String[] row)
-
parse
public final void parse(java.io.File file)
Parses the entirety of a given file and delegates each parsed row to an instance ofRowProcessor
, defined byCommonParserSettings.getRowProcessor()
.- Parameters:
file
- The file to be parsed.
-
parse
public final void parse(java.io.File file, java.lang.String encoding)
Parses the entirety of a given file and delegates each parsed row to an instance ofRowProcessor
, defined byCommonParserSettings.getRowProcessor()
.- Parameters:
file
- The file to be parsed.encoding
- the encoding of the file
-
parse
public final void parse(java.io.File file, java.nio.charset.Charset encoding)
Parses the entirety of a given file and delegates each parsed row to an instance ofRowProcessor
, defined byCommonParserSettings.getRowProcessor()
.- Parameters:
file
- The file to be parsed.encoding
- the encoding of the file
-
parse
public final void parse(java.io.InputStream input)
Parses the entirety of a given input and delegates each parsed row to an instance ofRowProcessor
, defined byCommonParserSettings.getRowProcessor()
.- Parameters:
input
- The input to be parsed. The input stream will be closed automatically, unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
.
-
parse
public final void parse(java.io.InputStream input, java.lang.String encoding)
Parses the entirety of a given input and delegates each parsed row to an instance ofRowProcessor
, defined byCommonParserSettings.getRowProcessor()
.- Parameters:
input
- The input to be parsed. The input stream will be closed automatically, unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
.encoding
- the encoding of the input stream
-
parse
public final void parse(java.io.InputStream input, java.nio.charset.Charset encoding)
Parses the entirety of a given input and delegates each parsed row to an instance ofRowProcessor
, defined byCommonParserSettings.getRowProcessor()
.- Parameters:
input
- The input to be parsed. The input stream will be closed automatically, unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
.encoding
- the encoding of the input stream
-
beginParsing
public final void beginParsing(java.io.File file)
Starts an iterator-style parsing cycle. If aRowProcessor
is provided in the configuration, it will be used to perform additional processing. The parsed records must be read one by one with the invocation ofparseNext()
. The user may invoke @linkstopParsing()
to stop reading from the input.- Parameters:
file
- The file to be parsed.
-
beginParsing
public final void beginParsing(java.io.File file, java.lang.String encoding)
Starts an iterator-style parsing cycle. If aRowProcessor
is provided in the configuration, it will be used to perform additional processing. The parsed records must be read one by one with the invocation ofparseNext()
. The user may invoke @linkstopParsing()
to stop reading from the input.- Parameters:
file
- The file to be parsed.encoding
- the encoding of the file
-
beginParsing
public final void beginParsing(java.io.File file, java.nio.charset.Charset encoding)
Starts an iterator-style parsing cycle. If aRowProcessor
is provided in the configuration, it will be used to perform additional processing. The parsed records must be read one by one with the invocation ofparseNext()
. The user may invoke @linkstopParsing()
to stop reading from the input.- Parameters:
file
- The file to be parsed.encoding
- the encoding of the file
-
beginParsing
public final void beginParsing(java.io.InputStream input)
Starts an iterator-style parsing cycle. If aRowProcessor
is provided in the configuration, it will be used to perform additional processing. The parsed records must be read one by one with the invocation ofparseNext()
. The user may invoke @linkstopParsing()
to stop reading from the input.- Parameters:
input
- The input to be parsed. The input stream will be closed automatically in case of errors unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
.
-
beginParsing
public final void beginParsing(java.io.InputStream input, java.lang.String encoding)
Starts an iterator-style parsing cycle. If aRowProcessor
is provided in the configuration, it will be used to perform additional processing. The parsed records must be read one by one with the invocation ofparseNext()
. The user may invoke @linkstopParsing()
to stop reading from the input.- Parameters:
input
- The input to be parsed. The input stream will be closed automatically in case of errors unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
.encoding
- the encoding of the input stream
-
beginParsing
public final void beginParsing(java.io.InputStream input, java.nio.charset.Charset encoding)
Starts an iterator-style parsing cycle. If aRowProcessor
is provided in the configuration, it will be used to perform additional processing. The parsed records must be read one by one with the invocation ofparseNext()
. The user may invoke @linkstopParsing()
to stop reading from the input.- Parameters:
input
- The input to be parsed. The input stream will be closed automatically in case of errors unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
.encoding
- the encoding of the input stream
-
parseAll
public final java.util.List<java.lang.String[]> parseAll(java.io.File file, int expectedRowCount)
Parses all records from a file and returns them in a list.- Parameters:
file
- the input file to be parsedexpectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all records parsed from the file.
-
parseAll
public final java.util.List<java.lang.String[]> parseAll(java.io.File file, java.lang.String encoding, int expectedRowCount)
Parses all records from a file and returns them in a list.- Parameters:
file
- the input file to be parsedencoding
- the encoding of the fileexpectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all records parsed from the file.
-
parseAll
public final java.util.List<java.lang.String[]> parseAll(java.io.File file, java.nio.charset.Charset encoding, int expectedRowCount)
Parses all records from a file and returns them in a list.- Parameters:
file
- the input file to be parsedencoding
- the encoding of the fileexpectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all records parsed from the file.
-
parseAll
public final java.util.List<java.lang.String[]> parseAll(java.io.InputStream input, int expectedRowCount)
Parses all records from an input stream and returns them in a list.- Parameters:
input
- the input stream to be parsed. The input stream will be closed automatically unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
expectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all records parsed from the input.
-
parseAll
public final java.util.List<java.lang.String[]> parseAll(java.io.InputStream input, java.lang.String encoding, int expectedRowCount)
Parses all records from an input stream and returns them in a list.- Parameters:
input
- the input stream to be parsed. The input stream will be closed automatically unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
encoding
- the encoding of the input streamexpectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all records parsed from the input.
-
parseAll
public final java.util.List<java.lang.String[]> parseAll(java.io.InputStream input, java.nio.charset.Charset encoding, int expectedRowCount)
Parses all records from an input stream and returns them in a list.- Parameters:
input
- the input stream to be parsed. The input stream will be closed automatically unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
encoding
- the encoding of the input streamexpectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all records parsed from the input.
-
parseAll
public final java.util.List<java.lang.String[]> parseAll(java.io.File file)
Parses all records from a file and returns them in a list.- Parameters:
file
- the input file to be parsed- Returns:
- the list of all records parsed from the file.
-
parseAll
public final java.util.List<java.lang.String[]> parseAll(java.io.File file, java.lang.String encoding)
Parses all records from a file and returns them in a list.- Parameters:
file
- the input file to be parsedencoding
- the encoding of the file- Returns:
- the list of all records parsed from the file.
-
parseAll
public final java.util.List<java.lang.String[]> parseAll(java.io.File file, java.nio.charset.Charset encoding)
Parses all records from a file and returns them in a list.- Parameters:
file
- the input file to be parsedencoding
- the encoding of the file- Returns:
- the list of all records parsed from the file.
-
parseAll
public final java.util.List<java.lang.String[]> parseAll(java.io.InputStream input)
Parses all records from an input stream and returns them in a list.- Parameters:
input
- the input stream to be parsed. The input stream will be closed automatically unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
- Returns:
- the list of all records parsed from the input.
-
parseAll
public final java.util.List<java.lang.String[]> parseAll(java.io.InputStream input, java.lang.String encoding)
Parses all records from an input stream and returns them in a list.- Parameters:
input
- the input stream to be parsed. The input stream will be closed automatically unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
encoding
- the encoding of the input stream- Returns:
- the list of all records parsed from the input.
-
parseAll
public final java.util.List<java.lang.String[]> parseAll(java.io.InputStream input, java.nio.charset.Charset encoding)
Parses all records from an input stream and returns them in a list.- Parameters:
input
- the input stream to be parsed. The input stream will be closed automatically unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
encoding
- the encoding of the input stream- Returns:
- the list of all records parsed from the input.
-
parseAllRecords
public final java.util.List<Record> parseAllRecords(java.io.File file, int expectedRowCount)
Parses all records from a file and returns them in a list.- Parameters:
file
- the input file to be parsedexpectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all records parsed from the file.
-
parseAllRecords
public final java.util.List<Record> parseAllRecords(java.io.File file, java.lang.String encoding, int expectedRowCount)
Parses all records from a file and returns them in a list.- Parameters:
file
- the input file to be parsedencoding
- the encoding of the fileexpectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all records parsed from the file.
-
parseAllRecords
public final java.util.List<Record> parseAllRecords(java.io.File file, java.nio.charset.Charset encoding, int expectedRowCount)
Parses all records from a file and returns them in a list.- Parameters:
file
- the input file to be parsedencoding
- the encoding of the fileexpectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all records parsed from the file.
-
parseAllRecords
public final java.util.List<Record> parseAllRecords(java.io.InputStream input, int expectedRowCount)
Parses all records from an input stream and returns them in a list.- Parameters:
input
- the input stream to be parsed. The input stream will be closed automatically unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
expectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all records parsed from the input.
-
parseAllRecords
public final java.util.List<Record> parseAllRecords(java.io.InputStream input, java.lang.String encoding, int expectedRowCount)
Parses all records from an input stream and returns them in a list.- Parameters:
input
- the input stream to be parsed. The input stream will be closed automatically unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
encoding
- the encoding of the input streamexpectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all records parsed from the input.
-
parseAllRecords
public final java.util.List<Record> parseAllRecords(java.io.InputStream input, java.nio.charset.Charset encoding, int expectedRowCount)
Parses all records from an input stream and returns them in a list.- Parameters:
input
- the input stream to be parsed. The input stream will be closed automatically unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
encoding
- the encoding of the input streamexpectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all records parsed from the input.
-
parseAllRecords
public final java.util.List<Record> parseAllRecords(java.io.File file)
Parses all records from a file and returns them in a list.- Parameters:
file
- the input file to be parsed- Returns:
- the list of all records parsed from the file.
-
parseAllRecords
public final java.util.List<Record> parseAllRecords(java.io.File file, java.lang.String encoding)
Parses all records from a file and returns them in a list.- Parameters:
file
- the input file to be parsedencoding
- the encoding of the file- Returns:
- the list of all records parsed from the file.
-
parseAllRecords
public final java.util.List<Record> parseAllRecords(java.io.File file, java.nio.charset.Charset encoding)
Parses all records from a file and returns them in a list.- Parameters:
file
- the input file to be parsedencoding
- the encoding of the file- Returns:
- the list of all records parsed from the file.
-
parseAllRecords
public final java.util.List<Record> parseAllRecords(java.io.InputStream input)
Parses all records from an input stream and returns them in a list.- Parameters:
input
- the input stream to be parsed. The input stream will be closed automatically unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
- Returns:
- the list of all records parsed from the input.
-
parseAllRecords
public final java.util.List<Record> parseAllRecords(java.io.InputStream input, java.lang.String encoding)
Parses all records from an input stream and returns them in a list.- Parameters:
input
- the input stream to be parsed. The input stream will be closed automatically unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
encoding
- the encoding of the input stream- Returns:
- the list of all records parsed from the input.
-
parseAllRecords
public final java.util.List<Record> parseAllRecords(java.io.InputStream input, java.nio.charset.Charset encoding)
Parses all records from an input stream and returns them in a list.- Parameters:
input
- the input stream to be parsed. The input stream will be closed automatically unlessCommonParserSettings.isAutoClosingEnabled()
evaluates tofalse
encoding
- the encoding of the input stream- Returns:
- the list of all records parsed from the input.
-
parseAllRecords
public final java.util.List<Record> parseAllRecords(java.io.Reader reader, int expectedRowCount)
Parses all records from the input and returns them in a list.- Parameters:
reader
- the input to be parsedexpectedRowCount
- expected number of rows to be parsed from the input. Used to pre-allocate the size of the outputList
- Returns:
- the list of all records parsed from the input.
-
internalParseAllRecords
private java.util.List<Record> internalParseAllRecords(boolean validateReader, java.io.Reader reader, int expectedRowCount)
-
parseAllRecords
public final java.util.List<Record> parseAllRecords(java.io.Reader reader)
Parses all records from the input and returns them in a list.- Parameters:
reader
- the input to be parsed- Returns:
- the list of all records parsed from the input.
-
parseNextRecord
public final Record parseNextRecord()
Parses the next record from the input. Note thatbeginParsing(Reader)
must have been invoked once before calling this method. If the end of the input is reached, then this method will return null. Additionally, all resources will be closed automatically at the end of the input or if any error happens while parsing.- Returns:
- The record parsed from the input or null if there's no more characters to read.
-
getComments
final java.util.Map<java.lang.Long,java.lang.String> getComments()
Returns all comments collected by the parser so far. An empty map will be returned ifCommonParserSettings.isCommentCollectionEnabled()
evaluates tofalse
.- Returns:
- a map containing the line numbers and comments found in each.
-
getLastComment
final java.lang.String getLastComment()
Returns the last comment found in the input.null
will be returned ifCommonParserSettings.isCommentCollectionEnabled()
is evaluated tofalse
.- Returns:
- the last comment found in the input.
-
getParsedHeaders
final java.lang.String[] getParsedHeaders()
Returns the headers parsed from the input, if and only ifCommonParserSettings.headerExtractionEnabled
istrue
. The result of this method won't return the list of headers manually set by the user inCommonSettings.getHeaders()
.- Returns:
- the headers parsed from the input, when
CommonParserSettings.headerExtractionEnabled
istrue
.
-
getContext
public final ParsingContext getContext()
Returns the current parsing context with information about the status of the parser at any given time.- Returns:
- the parsing context
-
getRecordMetadata
public final RecordMetaData getRecordMetadata()
Returns the metadata associated withRecord
s parsed from the input usingparseAllRecords(File)
orparseNextRecord()
.- Returns:
- the metadata of
Record
s generated with the current input.
-
iterate
public final IterableResult<java.lang.String[],ParsingContext> iterate(java.io.File input, java.lang.String encoding)
Provides anIterableResult
for iterating rows parsed from the input.- Parameters:
input
- the inputFile
encoding
- the encoding of the inputFile
- Returns:
- an iterator for rows parsed from the input.
-
iterate
public final IterableResult<java.lang.String[],ParsingContext> iterate(java.io.File input, java.nio.charset.Charset encoding)
Provides anIterableResult
for iterating rows parsed from the input.- Parameters:
input
- the inputFile
encoding
- the encoding of the inputFile
- Returns:
- an iterator for rows parsed from the input.
-
iterate
public final IterableResult<java.lang.String[],ParsingContext> iterate(java.io.File input)
Provides anIterableResult
for iterating rows parsed from the input.- Parameters:
input
- the inputFile
- Returns:
- an iterator for rows parsed from the input.
-
iterate
public final IterableResult<java.lang.String[],ParsingContext> iterate(java.io.Reader input)
Provides anIterableResult
for iterating rows parsed from the input.- Parameters:
input
- the inputReader
- Returns:
- an
iterable
over the results of parsing theReader
-
iterate
public final IterableResult<java.lang.String[],ParsingContext> iterate(java.io.InputStream input, java.lang.String encoding)
Provides anIterableResult
for iterating rows parsed from the input.- Parameters:
input
- the theInputStream
with contents to be parsedencoding
- the character encoding to be used for processing the given input.- Returns:
- an iterator for rows parsed from the input.
-
iterate
public final IterableResult<java.lang.String[],ParsingContext> iterate(java.io.InputStream input, java.nio.charset.Charset encoding)
Provides anIterableResult
for iterating rows parsed from the input.- Parameters:
input
- the theInputStream
with contents to be parsedencoding
- the character encoding to be used for processing the given input.- Returns:
- an iterator for rows parsed from the input.
-
iterate
public final IterableResult<java.lang.String[],ParsingContext> iterate(java.io.InputStream input)
Provides anIterableResult
for iterating rows parsed from the input.- Parameters:
input
- the theInputStream
with contents to be parsed- Returns:
- an iterator for rows parsed from the input.
-
iterateRecords
public final IterableResult<Record,ParsingContext> iterateRecords(java.io.File input, java.lang.String encoding)
Provides anIterableResult
for iterating records parsed from the input.- Parameters:
input
- the inputFile
encoding
- the encoding of the inputFile
- Returns:
- an iterator for records parsed from the input.
-
iterateRecords
public final IterableResult<Record,ParsingContext> iterateRecords(java.io.File input, java.nio.charset.Charset encoding)
Provides anIterableResult
for iterating records parsed from the input.- Parameters:
input
- the inputFile
encoding
- the encoding of the inputFile
- Returns:
- an iterator for records parsed from the input.
-
iterateRecords
public final IterableResult<Record,ParsingContext> iterateRecords(java.io.File input)
Provides anIterableResult
for iterating records parsed from the input.- Parameters:
input
- the inputFile
- Returns:
- an iterator for records parsed from the input.
-
iterateRecords
public final IterableResult<Record,ParsingContext> iterateRecords(java.io.Reader input)
Provides anIterableResult
for iterating records parsed from the input.- Parameters:
input
- the inputReader
- Returns:
- an iterator for records parsed from the input.
-
iterateRecords
public final IterableResult<Record,ParsingContext> iterateRecords(java.io.InputStream input, java.lang.String encoding)
Provides anIterableResult
for iterating records parsed from the input.- Parameters:
input
- the theInputStream
with contents to be parsedencoding
- the character encoding to be used for processing the given input.- Returns:
- an iterator for records parsed from the input.
-
iterateRecords
public final IterableResult<Record,ParsingContext> iterateRecords(java.io.InputStream input, java.nio.charset.Charset encoding)
Provides anIterableResult
for iterating records parsed from the input.- Parameters:
input
- the theInputStream
with contents to be parsedencoding
- the character encoding to be used for processing the given input.- Returns:
- an iterator for records parsed from the input.
-
iterateRecords
public final IterableResult<Record,ParsingContext> iterateRecords(java.io.InputStream input)
Provides anIterableResult
for iterating records parsed from the input.- Parameters:
input
- the theInputStream
with contents to be parsed- Returns:
- an iterator for records parsed from the input.
-
-