|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.univocity.parsers.common.input.AbstractCharInputReader
public abstract class AbstractCharInputReader
The base class for implementing different flavours of CharInputReader.
It provides the essential conversion of sequences of newline characters defined by Format.getLineSeparator() into the normalized newline character provided in Format.getNormalizedNewline().
It also provides a default implementation for most of the methods specified by the CharInputReader interface.
Extending classes must essentially read characters from a given Reader and assign it to the public buffer when requested (in the reloadBuffer() method).
Format,
DefaultCharInputReader,
ConcurrentCharInputReader| Field Summary | |
|---|---|
char[] |
buffer
The buffer itself |
int |
i
Current position in the buffer |
int |
length
Number of characters available in the buffer. |
| Constructor Summary | |
|---|---|
AbstractCharInputReader(char normalizedLineSeparator)
Creates a new instance that attempts to detect the newlines used in the input automatically. |
|
AbstractCharInputReader(char[] lineSeparator,
char normalizedLineSeparator)
Creates a new instance with the mandatory characters for handling newlines transparently. |
|
| Method Summary | |
|---|---|
void |
addInputAnalysisProcess(InputAnalysisProcess inputAnalysisProcess)
Submits a custom InputAnalysisProcess to analyze the input buffer and potentially discover configuration options such as
column separators is CSV, data formats, etc. |
long |
charCount()
Returns the number of characters returned by CharInputReader.nextChar() at any given time. |
String |
currentParsedContent()
Returns a String with the input character sequence parsed to produce the current record. |
void |
enableNormalizeLineEndings(boolean normalizeLineEndings)
Indicates to the input reader that the parser is running in "escape" mode and new lines should be returned as-is to prevent modifying the content of the parsed value. |
char |
getChar()
Returns the last character returned by the CharInputReader.nextChar() method. |
char[] |
getLineSeparator()
Returns the line separator by this character input reader. |
String |
getString(char ch,
char stop,
boolean trim,
String nullValue)
Attempts to collect a String from the current position until a stop character is found on the input,
or a line ending is reached. |
long |
lineCount()
Returns the number of newlines read so far. |
void |
markRecordStart()
Marks the start of a new record in the input, used internally to calculate the result of CharInputReader.currentParsedContent() |
char |
nextChar()
Returns the next character in the input provided by the active Reader. |
String |
readComment()
Collects the comment line found on the input. |
protected abstract void |
reloadBuffer()
Informs the extending class that the buffer has been read entirely and requests for another batch of characters. |
protected abstract void |
setReader(Reader reader)
Passes the Reader provided in the start(Reader) method to the extending class so it can begin loading characters from it. |
void |
skipLines(long lines)
Skips characters in the input until the given number of lines is discarded. |
char |
skipWhitespace(char ch,
char stopChar1,
char stopChar2)
Skips characters from the current input position, until a non-whitespace character, or a stop character is found |
void |
start(Reader reader)
Initializes the CharInputReader implementation with a Reader which provides access to the input. |
| 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.input.CharInputReader |
|---|
stop |
| Field Detail |
|---|
public int i
public char[] buffer
public int length
| Constructor Detail |
|---|
public AbstractCharInputReader(char normalizedLineSeparator)
normalizedLineSeparator - the normalized newline character (as defined in Format.getNormalizedNewline()) that is used to replace any lineSeparator sequence found in the input.
public AbstractCharInputReader(char[] lineSeparator,
char normalizedLineSeparator)
lineSeparator - the sequence of characters that represent a newline, as defined in Format.getLineSeparator()normalizedLineSeparator - the normalized newline character (as defined in Format.getNormalizedNewline()) that is used to replace any lineSeparator sequence found in the input.| Method Detail |
|---|
protected abstract void setReader(Reader reader)
Reader provided in the start(Reader) method to the extending class so it can begin loading characters from it.
reader - the Reader provided in start(Reader)protected abstract void reloadBuffer()
buffer attribute, as well as the number of characters available to the public length attribute.
To notify the input does not have any more characters, length must receive the -1 value
public final void start(Reader reader)
CharInputReaderReader which provides access to the input.
start in interface CharInputReaderreader - A Reader that provides access to the input.public final void addInputAnalysisProcess(InputAnalysisProcess inputAnalysisProcess)
InputAnalysisProcess to analyze the input buffer and potentially discover configuration options such as
column separators is CSV, data formats, etc. The process will be execute only once.
inputAnalysisProcess - a custom process to analyze the contents of the input buffer.public final char nextChar()
CharInputReaderReader.
If the input contains a sequence of newline characters (defined by Format.getLineSeparator()), this method will automatically converted them to the newline character specified in Format.getNormalizedNewline().
A subsequent call to this method will return the character after the newline sequence.
nextChar in interface CharInputReaderpublic final char getChar()
CharInputReaderCharInputReader.nextChar() method.
getChar in interface CharInputReaderCharInputReader.nextChar() method.'\0' if there are no more characters in the input or if the CharInputReader was stopped.public final long lineCount()
CharInputReader
lineCount in interface CharInputReaderpublic final void skipLines(long lines)
CharInputReader
skipLines in interface CharInputReaderlines - the number of lines to skip from the current location in the inputpublic String readComment()
CharInputReader
readComment in interface CharInputReaderpublic final long charCount()
CharInputReaderCharInputReader.nextChar() at any given time.
charCount in interface CharInputReaderCharInputReader.nextChar()public final void enableNormalizeLineEndings(boolean normalizeLineEndings)
CharInputReader
enableNormalizeLineEndings in interface CharInputReadernormalizeLineEndings - flag indicating that the parser is escaping values and line separators are to be returned as-is.public char[] getLineSeparator()
CharInputReaderFormat.getLineSeparator() configuration, or the line separator sequence identified automatically
when CommonParserSettings.isLineSeparatorDetectionEnabled() evaluates to true.
getLineSeparator in interface CharInputReader
public final char skipWhitespace(char ch,
char stopChar1,
char stopChar2)
CharInputReader
skipWhitespace in interface CharInputReaderch - the current character of the inputstopChar1 - the first stop character (which can be a whitespace)stopChar2 - the second character (which can be a whitespace)
public final String currentParsedContent()
CharInputReader
currentParsedContent in interface CharInputReaderpublic final void markRecordStart()
CharInputReaderCharInputReader.currentParsedContent()
markRecordStart in interface CharInputReader
public String getString(char ch,
char stop,
boolean trim,
String nullValue)
CharInputReaderString from the current position until a stop character is found on the input,
or a line ending is reached. If the String can be obtained, the current position of the parser will be updated to
the last consumed character. If the internal buffer needs to be reloaded, this method will return null
and the current position of the buffer will remain unchanged.
getString in interface CharInputReaderch - the current character to be considered. If equal to the stop character the nullValue will be returnedstop - the stop character that identifies the end of the content to be collectedtrim - flag indicating whether or not trailing whitespaces should be discardednullValue - value to return when the length of the content to be returned is 0.
String found on the input, or null if the buffer needs to reloaded.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||