|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.univocity.parsers.common.input.LookaheadCharInputReader
public class LookaheadCharInputReader
A special implementation of CharInputReader that wraps another CharInputReader and
collects a sequence of characters from the wrapped input, in order to analyze what the buffer contains
ahead of the current position.
| Constructor Summary | |
|---|---|
LookaheadCharInputReader(CharInputReader reader,
char newLine,
int whitespaceRangeStart)
Creates a lookahead input reader by wrapping a given CharInputReader implementation |
|
| Method Summary | |
|---|---|
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 escaping)
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 |
getLookahead()
Returns the current lookahead value. |
String |
getLookahead(char current)
Returns the lookahead value prepended with the current character |
String |
getString(char ch,
char stop,
boolean trim,
String nullValue,
int maxLength)
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 |
lookahead(int numberOfCharacters)
Fills the lookahead buffer with a given number of characters that will be extracted from the wrapped CharInputReader |
void |
markRecordStart()
Marks the start of a new record in the input, used internally to calculate the result of CharInputReader.currentParsedContent() |
boolean |
matches(char[] sequence,
char wildcard)
Matches a sequence of characters against the current lookahead buffer. |
boolean |
matches(char current,
char[] sequence,
char wildcard)
Matches a sequence of characters against the current lookahead buffer. |
char |
nextChar()
Returns the next character in the input provided by the active Reader. |
String |
readComment()
Collects the comment line found on the input. |
void |
skipLines(long lineCount)
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. |
void |
stop()
Stops the CharInputReader from reading characters from the Reader provided in CharInputReader.start(Reader) and closes it. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public LookaheadCharInputReader(CharInputReader reader,
char newLine,
int whitespaceRangeStart)
CharInputReader implementation
reader - the input reader whose characters will read and stored in a limited internal buffer,
in order to allow a parser to query what the characters are available ahead of the current input position.newLine - the normalized character that represents a line ending. Used internally as a stop character.whitespaceRangeStart - starting range of characters considered to be whitespace.| Method Detail |
|---|
public boolean matches(char current,
char[] sequence,
char wildcard)
current - the last character used by the parser, which should match the first character in the lookahead buffersequence - the expected sequence of characters after the current character, that are expected appear in the current lookahead bufferwildcard - character used in the sequence as a wildcard (e.g. * or ?), meaning any character is acceptable in its place.
true if the current character and the sequence characters that follows are present in the lookahead, otherwise false
public boolean matches(char[] sequence,
char wildcard)
sequence - the expected sequence of characters that are expected appear in the current lookahead bufferwildcard - character used in the sequence as a wildcard (e.g. * or ?), meaning any character is acceptable in its place.
true if the given sequence of characters is present in the lookahead, otherwise falsepublic String getLookahead()
String if the lookahead buffer is empty.public String getLookahead(char current)
current - the current character obtained by the parser
String formed by the given character followed by the lookahead value (if any).public void lookahead(int numberOfCharacters)
CharInputReader
numberOfCharacters - the number of characters to read from the wrapped CharInputReader, given in the constructor of this class.public void start(Reader reader)
CharInputReaderReader which provides access to the input.
start in interface CharInputReaderreader - A Reader that provides access to the input.public void stop()
CharInputReaderReader provided in CharInputReader.start(Reader) and closes it.
stop in interface CharInputReaderpublic 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 CharInputnextChar in interface CharInputReaderpublic long charCount()
CharInputReaderCharInputReader.nextChar() at any given time.
charCount in interface CharInputReaderCharInputReader.nextChar()public long lineCount()
CharInputReader
lineCount in interface CharInputReaderpublic void skipLines(long lineCount)
CharInputReader
skipLines in interface CharInputReaderlineCount - the number of lines to skip from the current location in the inputpublic void enableNormalizeLineEndings(boolean escaping)
CharInputReader
enableNormalizeLineEndings in interface CharInputReaderescaping - flag indicating that the parser is escaping values and line separators are to be returned as-is.public String readComment()
CharInputReader
readComment in interface CharInputReaderpublic char[] getLineSeparator()
CharInputReaderFormat.getLineSeparator() configuration, or the line separator sequence identified automatically
when CommonParserSettings.isLineSeparatorDetectionEnabled() evaluates to true.
getLineSeparator in interface CharInputReaderpublic final char getChar()
CharInputReaderCharInputReader.nextChar() method.
getChar in interface CharInputgetChar in interface CharInputReaderCharInputReader.nextChar() method.'\0' if there are no more characters in the input or if the CharInputReader was stopped.
public 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 String currentParsedContent()
CharInputReader
currentParsedContent in interface CharInputReaderpublic void markRecordStart()
CharInputReaderCharInputReader.currentParsedContent()
markRecordStart in interface CharInputReader
public String getString(char ch,
char stop,
boolean trim,
String nullValue,
int maxLength)
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.maxLength - the maximum length of the String to be returned. If the length exceeds this limit, null will be returned
String found on the input, or null if the buffer needs to reloaded or the maximum length has been exceeded.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||