Interface ParsingContext
-
- All Superinterfaces:
Context
- All Known Implementing Classes:
DefaultParsingContext,ParsingContextSnapshot,ParsingContextWrapper
public interface ParsingContext extends Context
Parsing context information available to instances ofRowProcessor.The ParsingContext can be used to control and to obtain information about the parsing process.
- Author:
- Univocity Software Pty Ltd - parsers@univocity.com
- See Also:
RowProcessor,DefaultParsingContext
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleancolumnsReordered()Indicates whether selected fields (usingCommonSettings.selectFields(java.lang.String...)and friends) are being reordered.java.util.Map<java.lang.Long,java.lang.String>comments()Returns all comments collected by the parser so far.longcurrentChar()Returns the index of the last char read from the input so far.longcurrentLine()Returns the current line of text being processed by the parserjava.lang.StringcurrentParsedContent()Returns a String with the input character sequence parsed to produce the current record.intcurrentParsedContentLength()Returns the length of the character sequence parsed to produce the current record.int[]extractedFieldIndexes()Returns the indexes of each field extracted from the input when fields are selected in the parser settings (i.e.java.lang.StringfieldContentOnError()Returns a String with the input character sequence accumulated on a field beforeTextParsingExceptionoccurred.java.lang.String[]headers()Returns the file headers that identify each parsed record.java.lang.StringlastComment()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.headerExtractionEnabledistrue.voidskipLines(long lines)Skips a given number of lines from the current position.-
Methods inherited from interface com.univocity.parsers.common.Context
currentColumn, currentRecord, errorContentLength, indexOf, indexOf, isStopped, recordMetaData, selectedHeaders, stop, toRecord
-
-
-
-
Method Detail
-
headers
java.lang.String[] headers()
Returns the file headers that identify each parsed record.If the headers are extracted from the input (i.e.
CommonParserSettings.isHeaderExtractionEnabled()== true), then these values will be returned.If no headers are extracted from the input, then the configured headers in
CommonSettings.getHeaders()will be returned. Note that the user-provided headers will override the header list parsed from the input, if any. To obtain the original list of headers found in the input useparsedHeaders()- Specified by:
headersin interfaceContext- Returns:
- the headers used to identify each record parsed from the input.
- See Also:
CommonParserSettings,CommonSettings
-
extractedFieldIndexes
int[] extractedFieldIndexes()
Returns the indexes of each field extracted from the input when fields are selected in the parser settings (i.e. usingCommonSettings.selectFields(java.lang.String...)and friends).The indexes are relative to their original position in the input.
For example, if the input has the fields "A, B, C, D", and the selected fields are "A, D", then the extracted field indexes will return [0, 3]
If no fields were selected, then this method will return null. This means all fields are being parsed.
- Specified by:
extractedFieldIndexesin interfaceContext- Returns:
- The indexes of each selected field; null if no fields were selected.
- See Also:
CommonSettings
-
columnsReordered
boolean columnsReordered()
Indicates whether selected fields (usingCommonSettings.selectFields(java.lang.String...)and friends) are being reordered.If columns are reordered, each parsed record will contain values only for the selected fields, as specified by
CommonParserSettings.isColumnReorderingEnabled()- Specified by:
columnsReorderedin interfaceContext- Returns:
- true if the parsed records are being reordered by the parser, false otherwise
- See Also:
CommonParserSettings,CommonSettings
-
currentLine
long currentLine()
Returns the current line of text being processed by the parser- Returns:
- current line of text being processed by the parser
-
currentChar
long currentChar()
Returns the index of the last char read from the input so far.- Returns:
- the index of the last char read from the input so far.
-
skipLines
void skipLines(long lines)
Skips a given number of lines from the current position.- Parameters:
lines- the number of lines to be skipped.
-
parsedHeaders
java.lang.String[] parsedHeaders()
Returns the headers parsed from the input, if and only ifCommonParserSettings.headerExtractionEnabledistrue. The result of this method won't return the list of headers manually set by the user inCommonSettings.getHeaders(). Use theheaders()method instead to obtain the headers actually used by the parser.- Returns:
- the headers parsed from the input, when
CommonParserSettings.headerExtractionEnabledistrue.
-
currentParsedContent
java.lang.String currentParsedContent()
Returns a String with the input character sequence parsed to produce the current record.- Returns:
- the text content parsed for the current input record.
-
currentParsedContentLength
int currentParsedContentLength()
Returns the length of the character sequence parsed to produce the current record.- Returns:
- the length of the text content parsed for the current input record
-
fieldContentOnError
java.lang.String fieldContentOnError()
Returns a String with the input character sequence accumulated on a field beforeTextParsingExceptionoccurred.- Returns:
- the text content parsed for the current field of the current input record at the time of the error.
-
comments
java.util.Map<java.lang.Long,java.lang.String> comments()
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.
-
lastComment
java.lang.String lastComment()
Returns the last comment found in the input.nullwill be returned ifCommonParserSettings.isCommentCollectionEnabled()is evaluated tofalse.- Returns:
- the last comment found in the input.
-
lineSeparator
char[] lineSeparator()
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.- Returns:
- the line separator sequence. Might contain one or two characters.
-
-