Class ParsingReader
- Direct Known Subclasses:
CombinedLogReader
Abstract super-class for obtaining records from a text stream using a parser.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.northconcepts.datapipeline.core.DataEndpoint
DataEndpoint.State -
Field Summary
FieldsFields inherited from class com.northconcepts.datapipeline.core.AbstractReader
currentRecord, fieldNames, lastRow, startingRowFields inherited from class com.northconcepts.datapipeline.core.DataReader
fieldLineage, recordLineageFields inherited from class com.northconcepts.datapipeline.core.DataEndpoint
lastRecord, PRODUCT, PRODUCT_VERSION, VENDOR, XML_INPUT_FACTORY_KEYFields inherited from class com.northconcepts.datapipeline.core.Endpoint
BUFFER_SIZE, captureElapsedTime, DEFAULT_READ_BUFFER_SIZEFields inherited from class com.northconcepts.datapipeline.core.DataObject
id, log, name, TIMESTAMP_FORMAT -
Constructor Summary
ConstructorsConstructorDescriptionParsingReader(File file) Creates a reader for the file using the default charset; the file is opened by this constructor rather than byopen().ParsingReader(File file, String charsetName) ParsingReader(Reader reader) -
Method Summary
Modifier and TypeMethodDescriptionaddExceptionProperties(DataException exception) Adds this endpoint's current state to aDataException.protected RecordaddLineage(Record record) Called byDataReader.read()for each record fromDataReader.readImpl()while lineage is saved; the default copiesrecordLineageinto every field along with its original index and name.intReturns the number of records that can probably be read without blocking.protected booleanfillRecord(Record record) Populates the given record with the next row's values; returns false at the end of the input.Returns the charset name given to the constructor or null if the default charset or aReaderis used.longReturns the current 0-based line number, i.e.protected booleanisDigit(int c) Indicates if the character is an ASCII digit (0-9).protected booleanisLetter(int c) Indicates if the character is an ASCII letter (a-z or A-Z).booleanIndicates if this reader can capture record and field lineage (false unless overridden by a reader that supports it).protected booleanisNewLine(int c) Indicates if the character is a carriage return or line feed.protected voidmatch(int c) Consumes the given character and appends it tovalueBuffer, throwing if the next character differs.protected voidConsumes one ASCII letter and appends it tovalueBuffer, throwing if the next character is not a letter.protected voidConsumes one digit (0-9) and appends it tovalueBuffer, throwing if the next character is not a digit.protected voidConsumes one or more digits and appends them tovalueBuffer.protected voidConsumes a decimal number such as1,234.56or.5and appends it, without the commas, tovalueBuffer.protected voidConsumes an integer that may contain grouping commas and appends its digits tovalueBuffer.protected voidConsumes the rest of the current line, appending it tovalueBuffer, followed by its line break if there is one.protected voidConsumes one line break (LF, CR or CR LF), increments the line number and starts a new parser column count; throws if there is no line break.protected voidConsumes one or more consecutive line breaks (LF, CR or CR LF), counting each ingetLineNumber().voidopen()Makes this endpoint ready for reading or writing.protected booleanIndicates if the next character is an ASCII letter, without consuming it.Methods inherited from class com.northconcepts.datapipeline.core.AbstractReader
getFieldNames, getLastRow, getStartingRow, isFieldNamesInFirstRow, isSkipEmptyRows, read, readImpl, setFieldNames, setFieldNames, setFieldNamesInFirstRow, setLastRow, setSkipEmptyRows, setStartingRowMethods inherited from class com.northconcepts.datapipeline.core.DataReader
getBufferSize, getNestedEndpoint, getNestedReader, getReader, getRootEndpoint, getRootReader, isExhausted, isSaveLineage, peek, pop, push, setSaveLineage, skipMethods inherited from class com.northconcepts.datapipeline.core.DataEndpoint
close, decrementRecordCount, enableJmx, getLastRecord, getRecordCount, getRecordCountAsBigInteger, getRecordCountAsString, incrementRecordCount, isRecordCountBigInteger, resetRecordCount, toStringMethods inherited from class com.northconcepts.datapipeline.core.Endpoint
addElapsedtime, assertClosed, assertNotOpened, assertOpened, finalize, getClosedOn, getDescription, getElapsedTime, getElapsedTimeAsString, getOpenedOn, getOpenElapsedTime, getOpenElapsedTimeAsString, getSelfTime, getSelfTimeAsString, getState, isCaptureElapsedTime, isClosed, isOpen, setCaptureElapsedTime, setDescription
-
Field Details
-
parser
-
valueBuffer
-
lineNumber
protected long lineNumber
-
-
Constructor Details
-
ParsingReader
Creates a reader for the file using the default charset; the file is opened by this constructor rather than byopen(). -
ParsingReader
-
ParsingReader
-
-
Method Details
-
getLineNumber
public long getLineNumber()Returns the current 0-based line number, i.e. the number of line breaks consumed so far. -
getCharsetName
Returns the charset name given to the constructor or null if the default charset or aReaderis used. -
open
Description copied from class:DataEndpointMakes this endpoint ready for reading or writing.- Overrides:
openin classAbstractReader- Throws:
DataException
-
available
public int available()Description copied from class:DataReaderReturns the number of records that can probably be read without blocking.- Overrides:
availablein classDataReader
-
addExceptionProperties
Description copied from class:EndpointAdds this endpoint's current state to aDataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.- Overrides:
addExceptionPropertiesin classAbstractReader
-
fillRecord
Description copied from class:AbstractReaderPopulates the given record with the next row's values; returns false at the end of the input.- Specified by:
fillRecordin classAbstractReader- Throws:
Throwable
-
matchDOUBLE
protected void matchDOUBLE()Consumes a decimal number such as1,234.56or.5and appends it, without the commas, tovalueBuffer. -
matchINTEGER
protected void matchINTEGER()Consumes an integer that may contain grouping commas and appends its digits tovalueBuffer. -
matchDIGITS
protected void matchDIGITS()Consumes one or more digits and appends them tovalueBuffer. -
matchDIGIT
protected void matchDIGIT()Consumes one digit (0-9) and appends it tovalueBuffer, throwing if the next character is not a digit. -
peekCHARACTER
protected boolean peekCHARACTER()Indicates if the next character is an ASCII letter, without consuming it. -
matchCHARACTER
protected void matchCHARACTER()Consumes one ASCII letter and appends it tovalueBuffer, throwing if the next character is not a letter. -
matchNEWLINES
protected void matchNEWLINES()Consumes one or more consecutive line breaks (LF, CR or CR LF), counting each ingetLineNumber(). -
matchNEWLINE
protected void matchNEWLINE()Consumes one line break (LF, CR or CR LF), increments the line number and starts a new parser column count; throws if there is no line break. -
matchLINE
protected void matchLINE()Consumes the rest of the current line, appending it tovalueBuffer, followed by its line break if there is one. -
isLetter
protected boolean isLetter(int c) Indicates if the character is an ASCII letter (a-z or A-Z). -
isDigit
protected boolean isDigit(int c) Indicates if the character is an ASCII digit (0-9). -
isNewLine
protected boolean isNewLine(int c) Indicates if the character is a carriage return or line feed. -
match
protected void match(int c) Consumes the given character and appends it tovalueBuffer, throwing if the next character differs. -
isLineageSupported
public boolean isLineageSupported()Description copied from class:DataReaderIndicates if this reader can capture record and field lineage (false unless overridden by a reader that supports it).- Overrides:
isLineageSupportedin classDataReader
-
addLineage
Description copied from class:DataReaderCalled byDataReader.read()for each record fromDataReader.readImpl()while lineage is saved; the default copiesrecordLineageinto every field along with its original index and name. Overrides set their source details onrecordLineagefirst and end withsuper.addLineage(record).- Overrides:
addLineagein classDataReader
-