Package com.univocity.parsers.common
Class DefaultContext
- java.lang.Object
-
- com.univocity.parsers.common.DefaultContext
-
- All Implemented Interfaces:
Context
- Direct Known Subclasses:
DefaultParsingContext
public class DefaultContext extends java.lang.Object implements Context
Default implementation of theContextinterface with essential information about the output being produced.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) ColumnMapcolumnMap(package private) interrorContentLength(package private) ParserOutputoutputprotected RecordFactoryrecordFactoryprotected booleanstopped
-
Constructor Summary
Constructors Constructor Description DefaultContext(int errorContentLength)DefaultContext(ParserOutput output, int errorContentLength)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancolumnsReordered()Indicates whether selected fields are being reordered.intcurrentColumn()Returns the column index of the record being processed.longcurrentRecord()Returns the index of the last valid record parsed from the inputinterrorContentLength()Returns the length limit of parsed contents appearing in exception messages when an error occursint[]extractedFieldIndexes()Returns the indexes of each field extracted from the input when fields are selected.java.lang.String[]headers()Returns the file headers that identify each parsed record.intindexOf(java.lang.Enum<?> header)Returns the position of a header (0 based).intindexOf(java.lang.String header)Returns the position of a header (0 based).booleanisStopped()Identifies whether the parser is running.RecordMetaDatarecordMetaData()Returns the metadata information associated with records produced by the current parsing process.(package private) voidreset()java.lang.String[]selectedHeaders()Returns the sequence of headers that have been selected.voidstop()Stops the parsing process.RecordtoRecord(java.lang.String[] row)Converts the given parsed row to aRecord
-
-
-
Field Detail
-
stopped
protected boolean stopped
-
output
final ParserOutput output
-
columnMap
final ColumnMap columnMap
-
errorContentLength
final int errorContentLength
-
recordFactory
protected RecordFactory recordFactory
-
-
Constructor Detail
-
DefaultContext
public DefaultContext(int errorContentLength)
-
DefaultContext
public DefaultContext(ParserOutput output, int errorContentLength)
-
-
Method Detail
-
headers
public java.lang.String[] headers()
Description copied from interface:ContextReturns the file headers that identify each parsed record.
-
selectedHeaders
public java.lang.String[] selectedHeaders()
Description copied from interface:ContextReturns the sequence of headers that have been selected. If no selection has been made, all available headers will be returned, producing the same output as a call to methodContext.headers().- Specified by:
selectedHeadersin interfaceContext- Returns:
- the sequence of selected headers, or all headers if no selection has been made.
-
extractedFieldIndexes
public int[] extractedFieldIndexes()
Description copied from interface:ContextReturns the indexes of each field extracted from the input when fields are selected.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
public boolean columnsReordered()
Description copied from interface:ContextIndicates whether selected fields are being reordered.If columns are reordered, each parsed record will contain values only for the selected fields, as specified by
Context.extractedFieldIndexes()- Specified by:
columnsReorderedin interfaceContext- Returns:
- true if the parsed records are being reordered by the parser, false otherwise
- See Also:
CommonParserSettings,CommonSettings
-
indexOf
public int indexOf(java.lang.String header)
Description copied from interface:ContextReturns the position of a header (0 based).
-
indexOf
public int indexOf(java.lang.Enum<?> header)
Description copied from interface:ContextReturns the position of a header (0 based).
-
reset
void reset()
-
currentColumn
public int currentColumn()
Description copied from interface:ContextReturns the column index of the record being processed.- Specified by:
currentColumnin interfaceContext- Returns:
- the column index of the record being processed.
-
currentRecord
public long currentRecord()
Description copied from interface:ContextReturns the index of the last valid record parsed from the input- Specified by:
currentRecordin interfaceContext- Returns:
- the index of the last valid record parsed from the input
-
stop
public void stop()
Description copied from interface:ContextStops the parsing process. Any open resources in use by the parser are closed automatically unlessCommonParserSettings.isAutoClosingEnabled()evaluates tofalse.
-
isStopped
public boolean isStopped()
Description copied from interface:ContextIdentifies whether the parser is running.
-
errorContentLength
public int errorContentLength()
Description copied from interface:ContextReturns the length limit of parsed contents appearing in exception messages when an error occursIf
0, then no exceptions will include the content being manipulated in their attributes, and the"<omitted>"string will appear in error messages as the parsed content.defaults to
.-1(no limit)- Specified by:
errorContentLengthin interfaceContext- Returns:
- the maximum length of the data content to display in exception messages
-
toRecord
public Record toRecord(java.lang.String[] row)
Description copied from interface:ContextConverts the given parsed row to aRecord
-
recordMetaData
public RecordMetaData recordMetaData()
Description copied from interface:ContextReturns the metadata information associated with records produced by the current parsing process.- Specified by:
recordMetaDatain interfaceContext- Returns:
- the record metadata.
-
-