Package com.univocity.parsers.common
Class DefaultParsingContext
- java.lang.Object
-
- com.univocity.parsers.common.DefaultContext
-
- com.univocity.parsers.common.DefaultParsingContext
-
- All Implemented Interfaces:
Context
,ParsingContext
public class DefaultParsingContext extends DefaultContext implements ParsingContext
The defaultParsingContext
implementation used internally byAbstractParser
to expose information about a parsing process in execution.- See Also:
ParsingContext
,AbstractParser
,RowProcessor
-
-
Field Summary
Fields Modifier and Type Field Description private CharInputReader
input
private AbstractParser<?>
parser
-
Fields inherited from class com.univocity.parsers.common.DefaultContext
columnMap, errorContentLength, output, recordFactory, stopped
-
-
Constructor Summary
Constructors Constructor Description DefaultParsingContext(AbstractParser<?> parser, int errorContentLength)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.Long,java.lang.String>
comments()
Returns all comments collected by the parser so far.long
currentChar()
Returns the index of the last char read from the input so far.long
currentLine()
Returns the current line of text being processed by the parserjava.lang.String
currentParsedContent()
Returns a String with the input character sequence parsed to produce the current record.int
currentParsedContentLength()
Returns the length of the character sequence parsed to produce the current record.java.lang.String
fieldContentOnError()
Returns a String with the input character sequence accumulated on a field beforeTextParsingException
occurred.java.lang.String
lastComment()
Returns the last comment found in the input.char[]
lineSeparator()
Returns the line separator characters used to separate individual records when parsing.java.lang.String[]
parsedHeaders()
Returns the headers parsed from the input, if and only ifCommonParserSettings.headerExtractionEnabled
istrue
.void
skipLines(long lines)
Skips a given number of lines from the current position.-
Methods inherited from class com.univocity.parsers.common.DefaultContext
columnsReordered, currentColumn, currentRecord, errorContentLength, extractedFieldIndexes, headers, indexOf, indexOf, isStopped, recordMetaData, reset, selectedHeaders, stop, toRecord
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.univocity.parsers.common.Context
currentColumn, currentRecord, errorContentLength, indexOf, indexOf, isStopped, recordMetaData, selectedHeaders, stop, toRecord
-
Methods inherited from interface com.univocity.parsers.common.ParsingContext
columnsReordered, extractedFieldIndexes, headers
-
-
-
-
Field Detail
-
input
private final CharInputReader input
-
parser
private final AbstractParser<?> parser
-
-
Constructor Detail
-
DefaultParsingContext
public DefaultParsingContext(AbstractParser<?> parser, int errorContentLength)
-
-
Method Detail
-
currentLine
public long currentLine()
Description copied from interface:ParsingContext
Returns the current line of text being processed by the parser- Specified by:
currentLine
in interfaceParsingContext
- Returns:
- current line of text being processed by the parser
-
currentChar
public long currentChar()
Description copied from interface:ParsingContext
Returns the index of the last char read from the input so far.- Specified by:
currentChar
in interfaceParsingContext
- Returns:
- the index of the last char read from the input so far.
-
skipLines
public void skipLines(long lines)
Description copied from interface:ParsingContext
Skips a given number of lines from the current position.- Specified by:
skipLines
in interfaceParsingContext
- Parameters:
lines
- the number of lines to be skipped.
-
fieldContentOnError
public java.lang.String fieldContentOnError()
Description copied from interface:ParsingContext
Returns a String with the input character sequence accumulated on a field beforeTextParsingException
occurred.- Specified by:
fieldContentOnError
in interfaceParsingContext
- Returns:
- the text content parsed for the current field of the current input record at the time of the error.
-
currentParsedContent
public java.lang.String currentParsedContent()
Description copied from interface:ParsingContext
Returns a String with the input character sequence parsed to produce the current record.- Specified by:
currentParsedContent
in interfaceParsingContext
- Returns:
- the text content parsed for the current input record.
-
currentParsedContentLength
public int currentParsedContentLength()
Description copied from interface:ParsingContext
Returns the length of the character sequence parsed to produce the current record.- Specified by:
currentParsedContentLength
in interfaceParsingContext
- Returns:
- the length of the text content parsed for the current input record
-
comments
public java.util.Map<java.lang.Long,java.lang.String> comments()
Description copied from interface:ParsingContext
Returns all comments collected by the parser so far. An empty map will be returned ifCommonParserSettings.isCommentCollectionEnabled()
evaluates tofalse
.- Specified by:
comments
in interfaceParsingContext
- Returns:
- a map containing the line numbers and comments found in each.
-
lastComment
public java.lang.String lastComment()
Description copied from interface:ParsingContext
Returns the last comment found in the input.null
will be returned ifCommonParserSettings.isCommentCollectionEnabled()
is evaluated tofalse
.- Specified by:
lastComment
in interfaceParsingContext
- Returns:
- the last comment found in the input.
-
parsedHeaders
public java.lang.String[] parsedHeaders()
Description copied from interface:ParsingContext
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()
. Use theParsingContext.headers()
method instead to obtain the headers actually used by the parser.- Specified by:
parsedHeaders
in interfaceParsingContext
- Returns:
- the headers parsed from the input, when
CommonParserSettings.headerExtractionEnabled
istrue
.
-
lineSeparator
public char[] lineSeparator()
Description copied from interface:ParsingContext
Returns the line separator characters used to separate individual records when parsing. This could be the line separator defined in theFormat.getLineSeparator()
configuration, or the line separator sequence identified automatically whenCommonParserSettings.isLineSeparatorDetectionEnabled()
evaluates totrue
.- Specified by:
lineSeparator
in interfaceParsingContext
- Returns:
- the line separator sequence. Might contain one or two characters.
-
-