Top Description Fields Constructors Methods
com.univocity.parsers.common.input

public Class LookaheadCharInputReader

extends Object
implements CharInputReader
Class Inheritance
All Implemented Interfaces
com.univocity.parsers.common.input.CharInputReader, com.univocity.parsers.common.input.CharInput
Imports
java.io.*, java.util.*

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.

Field Summary

Modifier and TypeField and Description
private char
private int
private char[]
private final char
private final CharInputReader
private int
private final int

Constructor Summary

AccessConstructor and Description
public
LookaheadCharInputReader(CharInputReader
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.
reader
,
char
the normalized character that represents a line ending. Used internally as a stop character.
newLine
,
int
starting range of characters considered to be whitespace.
whitespaceRangeStart
)

Creates a lookahead input reader by wrapping a given CharInputReader implementation

Method Summary

Modifier and TypeMethod and Description
public long
charCount()

Implements com.univocity.parsers.common.input.CharInputReader.charCount.

Returns the number of characters returned by CharInputReader#nextChar() at any given time.
public String
currentParsedContent()

Implements com.univocity.parsers.common.input.CharInputReader.currentParsedContent.

Returns a String with the input character sequence parsed to produce the current record.
public int
currentParsedContentLength()

Implements com.univocity.parsers.common.input.CharInputReader.currentParsedContentLength.

Returns the length of the character sequence parsed to produce the current record.
public void
enableNormalizeLineEndings(boolean
flag indicating that the parser is escaping values and line separators are to be returned as-is.
escaping
)

Implements com.univocity.parsers.common.input.CharInputReader.enableNormalizeLineEndings.

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.
public final char
getChar()

Implements com.univocity.parsers.common.input.CharInputReader.getChar.

Returns the last character returned by the nextChar() method.
public char[]
getLineSeparator()

Implements com.univocity.parsers.common.input.CharInputReader.getLineSeparator.

Returns the line separator by this character input reader.
public String

Returns:

the current lookahead value, or an empty String if the lookahead buffer is empty.
getLookahead
()

Returns the current lookahead value.

public String

Returns:

a String formed by the given character followed by the lookahead value (if any).
getLookahead
(char
the current character obtained by the parser
current
)

Returns the lookahead value prepended with the current character

public String
getQuotedString(char
the quote character
quote
,
char
the quote escape character
escape
,
char
the escape of the quote escape character
escapeEscape
,
int
the maximum length of the String to be returned. If the length exceeds this limit, null will be returned
maxLength
,
char
the first stop character that identifies the end of the content to be collected
stop1
,
char
the second stop character that identifies the end of the content to be collected
stop2
,
boolean
flag to indicate the quotes that wrap the resulting String should be kept.
keepQuotes
,
boolean
flag to indicate that escape sequences should be kept
keepEscape
,
boolean
flag to indicate leading whitespaces should be trimmed
trimLeading
,
boolean
flag to indicate that trailing whitespaces should be trimmed
trimTrailing
)

Implements com.univocity.parsers.common.input.CharInputReader.getQuotedString.

Attempts to collect a quoted String from the current position until a closing quote or stop character is found on the input, or a line ending is reached.
public String
getString(char
the current character to be considered. If equal to the stop character the nullValue will be returned
ch
,
char
the stop character that identifies the end of the content to be collected
stop
,
boolean
flag indicating whether or not trailing whitespaces should be discarded
trim
,
String
value to return when the length of the content to be returned is 0.
nullValue
,
int
the maximum length of the String to be returned. If the length exceeds this limit, null will be returned
maxLength
)

Implements com.univocity.parsers.common.input.CharInputReader.getString.

Attempts to collect a String from the current position until a stop character is found on the input, or a line ending is reached.
public int
lastIndexOf(char
the character to look for
ch
)

Implements com.univocity.parsers.common.input.CharInputReader.lastIndexOf.

Returns the last index of a given character in the current parsed content
public long
lineCount()

Implements com.univocity.parsers.common.input.CharInputReader.lineCount.

Returns the number of newlines read so far.
public void
lookahead(int
the number of characters to read from the wrapped CharInputReader, given in the constructor of this class.
numberOfCharacters
)

Fills the lookahead buffer with a given number of characters that will be extracted from the wrapped CharInputReader

public void
markRecordStart()

Implements com.univocity.parsers.common.input.CharInputReader.markRecordStart.

Marks the start of a new record in the input, used internally to calculate the result of currentParsedContent()
public boolean

Returns:

true if the current character and the sequence characters that follows are present in the lookahead, otherwise false
matches
(char
the last character used by the parser, which should match the first character in the lookahead buffer
current
,
char[]
the expected sequence of characters after the current character, that are expected appear in the current lookahead buffer
sequence
,
char
character used in the sequence as a wildcard (e.g. * or ?), meaning any character is acceptable in its place.
wildcard
)

Matches a sequence of characters against the current lookahead buffer.

public boolean

Returns:

true if the given sequence of characters is present in the lookahead, otherwise false
matches
(char[]
the expected sequence of characters that are expected appear in the current lookahead buffer
sequence
,
char
character used in the sequence as a wildcard (e.g. * or ?), meaning any character is acceptable in its place.
wildcard
)

Matches a sequence of characters against the current lookahead buffer.

public char
nextChar()

Implements com.univocity.parsers.common.input.CharInputReader.nextChar.

Returns the next character in the input provided by the active java.io.Reader.
public String
readComment()

Implements com.univocity.parsers.common.input.CharInputReader.readComment.

Collects the comment line found on the input.
public void
public void
skipLines(long
the number of lines to skip from the current location in the input
lineCount
)

Implements com.univocity.parsers.common.input.CharInputReader.skipLines.

Skips characters in the input until the given number of lines is discarded.
public boolean
skipQuotedString(char
the quote character
quote
,
char
the quote escape character
escape
,
char
the first stop character that identifies the end of the content to be collected
stop1
,
char
the second stop character that identifies the end of the content to be collected
stop2
)

Implements com.univocity.parsers.common.input.CharInputReader.skipQuotedString.

Attempts to skip a quoted String from the current position until a stop character is found on the input, or a line ending is reached.
public boolean
skipString(char
the current character to be considered. If equal to the stop character false will be returned
ch
,
char
the stop character that identifies the end of the content to be collected
stop
)

Implements com.univocity.parsers.common.input.CharInputReader.skipString.

Attempts to skip a String from the current position until a stop character is found on the input, or a line ending is reached.
public char
skipWhitespace(char
the current character of the input
ch
,
char
the first stop character (which can be a whitespace)
stopChar1
,
char
the second character (which can be a whitespace)
stopChar2
)

Implements com.univocity.parsers.common.input.CharInputReader.skipWhitespace.

Skips characters from the current input position, until a non-whitespace character, or a stop character is found
public void
start(Reader
A java.io.Reader that provides access to the input.
reader
)

Implements com.univocity.parsers.common.input.CharInputReader.start.

Initializes the CharInputReader implementation with a java.io.Reader which provides access to the input.
public void
stop()

Implements com.univocity.parsers.common.input.CharInputReader.stop.

Stops the CharInputReader from reading characters from the java.io.Reader provided in CharInputReader#start(Reader) and closes it.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delimiterback to summary
private char delimiter
lengthback to summary
private int length
lookaheadback to summary
private char[] lookahead
newLineback to summary
private final char newLine
readerback to summary
private final CharInputReader reader
startback to summary
private int start
whitespaceRangeStartback to summary
private final int whitespaceRangeStart

Constructor Detail

LookaheadCharInputReaderback to summary
public LookaheadCharInputReader(CharInputReader reader, char newLine, int whitespaceRangeStart)

Creates a lookahead input reader by wrapping a given CharInputReader implementation

Parameters
reader:CharInputReader

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:char

the normalized character that represents a line ending. Used internally as a stop character.

whitespaceRangeStart:int

starting range of characters considered to be whitespace.

Method Detail

charCountback to summary
public long charCount()

Implements com.univocity.parsers.common.input.CharInputReader.charCount.

Doc from com.univocity.parsers.common.input.CharInputReader.charCount.

Returns the number of characters returned by CharInputReader#nextChar() at any given time.

Returns:long

the number of characters returned by CharInputReader#nextChar()

Annotations
@Override
currentParsedContentback to summary
public String currentParsedContent()

Implements com.univocity.parsers.common.input.CharInputReader.currentParsedContent.

Doc from com.univocity.parsers.common.input.CharInputReader.currentParsedContent.

Returns a String with the input character sequence parsed to produce the current record.

Returns:String

the text content parsed for the current input record.

Annotations
@Override
currentParsedContentLengthback to summary
public int currentParsedContentLength()

Implements com.univocity.parsers.common.input.CharInputReader.currentParsedContentLength.

Doc from com.univocity.parsers.common.input.CharInputReader.currentParsedContentLength.

Returns the length of the character sequence parsed to produce the current record.

Returns:int

the length of the text content parsed for the current input record

Annotations
@Override
enableNormalizeLineEndingsback to summary
public void enableNormalizeLineEndings(boolean escaping)

Implements com.univocity.parsers.common.input.CharInputReader.enableNormalizeLineEndings.

Doc from com.univocity.parsers.common.input.CharInputReader.enableNormalizeLineEndings.

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.

Parameters
escaping:boolean

flag indicating that the parser is escaping values and line separators are to be returned as-is.

Annotations
@Override
getCharback to summary
public final char getChar()

Implements com.univocity.parsers.common.input.CharInputReader.getChar.

Doc from com.univocity.parsers.common.input.CharInputReader.getChar.

Returns the last character returned by the nextChar() method.

Returns:char

the last character returned by the nextChar() method.'\0' if there are no more characters in the input or if the CharInputReader was stopped.

Annotations
@Override
getLineSeparatorback to summary
public char[] getLineSeparator()

Implements com.univocity.parsers.common.input.CharInputReader.getLineSeparator.

Doc from com.univocity.parsers.common.input.CharInputReader.getLineSeparator.

Returns the line separator by this character input reader. This could be the line separator defined in the Format#getLineSeparator() configuration, or the line separator sequence identified automatically when CommonParserSettings#isLineSeparatorDetectionEnabled() evaluates to true.

Returns:char[]

the line separator in use.

Annotations
@Override
getLookaheadback to summary
public String getLookahead()

Returns the current lookahead value.

Returns:String

the current lookahead value, or an empty String if the lookahead buffer is empty.

getLookaheadback to summary
public String getLookahead(char current)

Returns the lookahead value prepended with the current character

Parameters
current:char

the current character obtained by the parser

Returns:String

a String formed by the given character followed by the lookahead value (if any).

getQuotedStringback to summary
public String getQuotedString(char quote, char escape, char escapeEscape, int maxLength, char stop1, char stop2, boolean keepQuotes, boolean keepEscape, boolean trimLeading, boolean trimTrailing)

Implements com.univocity.parsers.common.input.CharInputReader.getQuotedString.

Doc from com.univocity.parsers.common.input.CharInputReader.getQuotedString.

Attempts to collect a quoted String from the current position until a closing quote or 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.

Parameters
quote:char

the quote character

escape:char

the quote escape character

escapeEscape:char

the escape of the quote escape character

maxLength:int

the maximum length of the String to be returned. If the length exceeds this limit, null will be returned

stop1:char

the first stop character that identifies the end of the content to be collected

stop2:char

the second stop character that identifies the end of the content to be collected

keepQuotes:boolean

flag to indicate the quotes that wrap the resulting String should be kept.

keepEscape:boolean

flag to indicate that escape sequences should be kept

trimLeading:boolean

flag to indicate leading whitespaces should be trimmed

trimTrailing:boolean

flag to indicate that trailing whitespaces should be trimmed

Returns:String

the String found on the input, or null if the buffer needs to reloaded or the maximum length has been exceeded.

Annotations
@Override
getStringback to summary
public String getString(char ch, char stop, boolean trim, String nullValue, int maxLength)

Implements com.univocity.parsers.common.input.CharInputReader.getString.

Doc from com.univocity.parsers.common.input.CharInputReader.getString.

Attempts to collect a String 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.

Parameters
ch:char

the current character to be considered. If equal to the stop character the nullValue will be returned

stop:char

the stop character that identifies the end of the content to be collected

trim:boolean

flag indicating whether or not trailing whitespaces should be discarded

nullValue:String

value to return when the length of the content to be returned is 0.

maxLength:int

the maximum length of the String to be returned. If the length exceeds this limit, null will be returned

Returns:String

the String found on the input, or null if the buffer needs to reloaded or the maximum length has been exceeded.

Annotations
@Override
lastIndexOfback to summary
public int lastIndexOf(char ch)

Implements com.univocity.parsers.common.input.CharInputReader.lastIndexOf.

Doc from com.univocity.parsers.common.input.CharInputReader.lastIndexOf.

Returns the last index of a given character in the current parsed content

Parameters
ch:char

the character to look for

Returns:int

the last position of the given character in the current parsed content, or -1 if not found.

Annotations
@Override
lineCountback to summary
public long lineCount()

Implements com.univocity.parsers.common.input.CharInputReader.lineCount.

Doc from com.univocity.parsers.common.input.CharInputReader.lineCount.

Returns the number of newlines read so far.

Returns:long

the number of newlines read so far.

Annotations
@Override
lookaheadback to summary
public void lookahead(int numberOfCharacters)

Fills the lookahead buffer with a given number of characters that will be extracted from the wrapped CharInputReader

Parameters
numberOfCharacters:int

the number of characters to read from the wrapped CharInputReader, given in the constructor of this class.

markRecordStartback to summary
public void markRecordStart()

Implements com.univocity.parsers.common.input.CharInputReader.markRecordStart.

Doc from com.univocity.parsers.common.input.CharInputReader.markRecordStart.

Marks the start of a new record in the input, used internally to calculate the result of currentParsedContent()

Annotations
@Override
matchesback to summary
public boolean matches(char current, char[] sequence, char wildcard)

Matches a sequence of characters against the current lookahead buffer.

Parameters
current:char

the last character used by the parser, which should match the first character in the lookahead buffer

sequence:char[]

the expected sequence of characters after the current character, that are expected appear in the current lookahead buffer

wildcard:char

character used in the sequence as a wildcard (e.g. * or ?), meaning any character is acceptable in its place.

Returns:boolean

true if the current character and the sequence characters that follows are present in the lookahead, otherwise false

matchesback to summary
public boolean matches(char[] sequence, char wildcard)

Matches a sequence of characters against the current lookahead buffer.

Parameters
sequence:char[]

the expected sequence of characters that are expected appear in the current lookahead buffer

wildcard:char

character used in the sequence as a wildcard (e.g. * or ?), meaning any character is acceptable in its place.

Returns:boolean

true if the given sequence of characters is present in the lookahead, otherwise false

nextCharback to summary
public char nextChar()

Implements com.univocity.parsers.common.input.CharInputReader.nextChar.

Doc from com.univocity.parsers.common.input.CharInputReader.nextChar.

Returns the next character in the input provided by the active java.io.Reader.

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.

Returns:char

the next character in the input. '\0' if there are no more characters in the input or if the CharInputReader was stopped.

Annotations
@Override
readCommentback to summary
public String readComment()

Implements com.univocity.parsers.common.input.CharInputReader.readComment.

Doc from com.univocity.parsers.common.input.CharInputReader.readComment.

Collects the comment line found on the input.

Returns:String

the text found in the comment from the current position.

Annotations
@Override
reloadBufferback to summary
public void reloadBuffer()
skipLinesback to summary
public void skipLines(long lineCount)

Implements com.univocity.parsers.common.input.CharInputReader.skipLines.

Doc from com.univocity.parsers.common.input.CharInputReader.skipLines.

Skips characters in the input until the given number of lines is discarded.

Parameters
lineCount:long

the number of lines to skip from the current location in the input

Annotations
@Override
skipQuotedStringback to summary
public boolean skipQuotedString(char quote, char escape, char stop1, char stop2)

Implements com.univocity.parsers.common.input.CharInputReader.skipQuotedString.

Doc from com.univocity.parsers.common.input.CharInputReader.skipQuotedString.

Attempts to skip a quoted String from the current position until a stop character is found on the input, or a line ending is reached. If the String can be skipped, 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 false and the current position of the buffer will remain unchanged.

Parameters
quote:char

the quote character

escape:char

the quote escape character

stop1:char

the first stop character that identifies the end of the content to be collected

stop2:char

the second stop character that identifies the end of the content to be collected

Returns:boolean

true if an entire String value was found on the input and skipped, or false if the buffer needs to reloaded.

Annotations
@Override
skipStringback to summary
public boolean skipString(char ch, char stop)

Implements com.univocity.parsers.common.input.CharInputReader.skipString.

Doc from com.univocity.parsers.common.input.CharInputReader.skipString.

Attempts to skip a String from the current position until a stop character is found on the input, or a line ending is reached. If the String can be skipped, 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 false and the current position of the buffer will remain unchanged.

Parameters
ch:char

the current character to be considered. If equal to the stop character false will be returned

stop:char

the stop character that identifies the end of the content to be collected

Returns:boolean

true if an entire String value was found on the input and skipped, or false if the buffer needs to reloaded.

Annotations
@Override
skipWhitespaceback to summary
public char skipWhitespace(char ch, char stopChar1, char stopChar2)

Implements com.univocity.parsers.common.input.CharInputReader.skipWhitespace.

Doc from com.univocity.parsers.common.input.CharInputReader.skipWhitespace.

Skips characters from the current input position, until a non-whitespace character, or a stop character is found

Parameters
ch:char

the current character of the input

stopChar1:char

the first stop character (which can be a whitespace)

stopChar2:char

the second character (which can be a whitespace)

Returns:char

the first non-whitespace character (or delimiter) found in the input.

Annotations
@Override
startback to summary
public void start(Reader reader)

Implements com.univocity.parsers.common.input.CharInputReader.start.

Doc from com.univocity.parsers.common.input.CharInputReader.start.

Initializes the CharInputReader implementation with a java.io.Reader which provides access to the input.

Parameters
reader:Reader

A java.io.Reader that provides access to the input.

Annotations
@Override
stopback to summary
public void stop()

Implements com.univocity.parsers.common.input.CharInputReader.stop.

Doc from com.univocity.parsers.common.input.CharInputReader.stop.

Stops the CharInputReader from reading characters from the java.io.Reader provided in CharInputReader#start(Reader) and closes it.

Annotations
@Override