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

public Interface CharInputReader

extends CharInput
Known Direct Implementers
com.univocity.parsers.common.input.LookaheadCharInputReader, com.univocity.parsers.common.input.AbstractCharInputReader
Imports
com.univocity.parsers.common.*, java.io.*

The definition of a character input reader used by all univocity-parsers that extend AbstractParser.

This interface declares basic functionalities to provide a common input manipulation structure for all parser classes.

Implementations of this interface MUST convert the sequence of newline characters defined by Format#getLineSeparator() into the normalized newline character provided in Format#getNormalizedNewline().

Author
Univocity Software Pty Ltd - [email protected]
See Also
com.univocity.parsers.common.Format

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

the number of characters returned by CharInputReader#nextChar()
charCount
()

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

public String

Returns:

the text content parsed for the current input record.
currentParsedContent
()

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

public int

Returns:

the length of the text content parsed for the current input record
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
)

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 char

Returns:

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

Redeclares com.univocity.parsers.common.input.CharInput.getChar.

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

Returns:

the line separator in use.
getLineSeparator
()

Returns the line separator by this character input reader.

public String

Returns:

the String found on the input, or null if the buffer needs to reloaded or the maximum length has been exceeded.
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
)

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

Returns:

the String found on the input, or null if the buffer needs to reloaded or the maximum length has been exceeded.
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
)

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

Returns:

the last position of the given character in the current parsed content, or -1 if not found.
lastIndexOf
(char
the character to look for
ch
)

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

public long

Returns:

the number of newlines read so far.
lineCount
()

Returns the number of newlines read so far.

public void
markRecordStart()

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

public char

Returns:

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

Redeclares com.univocity.parsers.common.input.CharInput.nextChar.

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

Returns:

the text found in the comment from the current position.
readComment
()

Collects the comment line found on the input.

public void
skipLines(long
the number of lines to skip from the current location in the input
lineCount
)

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

public boolean

Returns:

true if an entire String value was found on the input and skipped, or false if the buffer needs to reloaded.
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
)

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

Returns:

true if an entire String value was found on the input and skipped, or false if the buffer needs to reloaded.
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
)

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

Returns:

the first non-whitespace character (or delimiter) found in the input.
skipWhitespace
(char
the current character of the input
current
,
char
the first stop character (which can be a whitespace)
stopChar1
,
char
the second character (which can be a whitespace)
stopChar2
)

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
)

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

public void
stop()

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

Method Detail

charCountback to summary
public long charCount()

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

Returns:long

the number of characters returned by CharInputReader#nextChar()

currentParsedContentback to summary
public String 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.

currentParsedContentLengthback to summary
public int 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

enableNormalizeLineEndingsback to summary
public 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.

Parameters
escaping:boolean

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

getCharback to summary
public char getChar()

Redeclares com.univocity.parsers.common.input.CharInput.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.

getLineSeparatorback to summary
public char[] 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.

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)

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.

getStringback to summary
public 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. 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.

lastIndexOfback to summary
public int lastIndexOf(char ch)

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.

lineCountback to summary
public long lineCount()

Returns the number of newlines read so far.

Returns:long

the number of newlines read so far.

markRecordStartback to summary
public void markRecordStart()

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

nextCharback to summary
public char nextChar()

Redeclares com.univocity.parsers.common.input.CharInput.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.

readCommentback to summary
public String readComment()

Collects the comment line found on the input.

Returns:String

the text found in the comment from the current position.

skipLinesback to summary
public void skipLines(long lineCount)

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

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

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.

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

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.

skipWhitespaceback to summary
public char skipWhitespace(char current, char stopChar1, char stopChar2)

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

Parameters
current: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.

startback to summary
public void start(Reader reader)

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.

stopback to summary
public void stop()

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