Interface CharInputReader
-
- All Superinterfaces:
CharInput
- All Known Implementing Classes:
AbstractCharInputReader,ConcurrentCharInputReader,DefaultCharInputReader,LookaheadCharInputReader
public interface CharInputReader extends CharInput
The definition of a character input reader used by all univocity-parsers that extendAbstractParser.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 inFormat.getNormalizedNewline().- See Also:
Format
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description longcharCount()Returns the number of characters returned bynextChar()at any given time.java.lang.StringcurrentParsedContent()Returns a String with the input character sequence parsed to produce the current record.intcurrentParsedContentLength()Returns the length of the character sequence parsed to produce the current record.voidenableNormalizeLineEndings(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.chargetChar()Returns the last character returned by thenextChar()method.char[]getLineSeparator()Returns the line separator by this character input reader.java.lang.StringgetQuotedString(char quote, char escape, char escapeEscape, int maxLength, char stop1, char stop2, boolean keepQuotes, boolean keepEscape, boolean trimLeading, boolean trimTrailing)Attempts to collect a quotedStringfrom the current position until a closing quote or stop character is found on the input, or a line ending is reached.java.lang.StringgetString(char ch, char stop, boolean trim, java.lang.String nullValue, int maxLength)Attempts to collect aStringfrom the current position until a stop character is found on the input, or a line ending is reached.intlastIndexOf(char ch)Returns the last index of a given character in the current parsed contentlonglineCount()Returns the number of newlines read so far.voidmarkRecordStart()Marks the start of a new record in the input, used internally to calculate the result ofcurrentParsedContent()charnextChar()Returns the next character in the input provided by the activeReader.java.lang.StringreadComment()Collects the comment line found on the input.voidskipLines(long lineCount)Skips characters in the input until the given number of lines is discarded.booleanskipQuotedString(char quote, char escape, char stop1, char stop2)Attempts to skip a quotedStringfrom the current position until a stop character is found on the input, or a line ending is reached.booleanskipString(char ch, char stop)Attempts to skip aStringfrom the current position until a stop character is found on the input, or a line ending is reached.charskipWhitespace(char current, char stopChar1, char stopChar2)Skips characters from the current input position, until a non-whitespace character, or a stop character is foundvoidstart(java.io.Reader reader)Initializes the CharInputReader implementation with aReaderwhich provides access to the input.voidstop()Stops the CharInputReader from reading characters from theReaderprovided instart(Reader)and closes it.
-
-
-
Method Detail
-
start
void start(java.io.Reader reader)
Initializes the CharInputReader implementation with aReaderwhich provides access to the input.- Parameters:
reader- AReaderthat provides access to the input.
-
stop
void stop()
Stops the CharInputReader from reading characters from theReaderprovided instart(Reader)and closes it.
-
nextChar
char nextChar()
Returns the next character in the input provided by the activeReader.If the input contains a sequence of newline characters (defined by
Format.getLineSeparator()), this method will automatically converted them to the newline character specified inFormat.getNormalizedNewline().A subsequent call to this method will return the character after the newline sequence.
-
getChar
char getChar()
Returns the last character returned by thenextChar()method.- Specified by:
getCharin interfaceCharInput- 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.
-
charCount
long charCount()
Returns the number of characters returned bynextChar()at any given time.- Returns:
- the number of characters returned by
nextChar()
-
lineCount
long lineCount()
Returns the number of newlines read so far.- Returns:
- the number of newlines read so far.
-
skipLines
void skipLines(long lineCount)
Skips characters in the input until the given number of lines is discarded.- Parameters:
lineCount- the number of lines to skip from the current location in the input
-
readComment
java.lang.String readComment()
Collects the comment line found on the input.- Returns:
- the text found in the comment from the current position.
-
enableNormalizeLineEndings
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- flag indicating that the parser is escaping values and line separators are to be returned as-is.
-
getLineSeparator
char[] getLineSeparator()
Returns the line separator by this character input reader. This could be the line separator defined in theFormat.getLineSeparator()configuration, or the line separator sequence identified automatically whenCommonParserSettings.isLineSeparatorDetectionEnabled()evaluates totrue.- Returns:
- the line separator in use.
-
skipWhitespace
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- the current character of the inputstopChar1- the first stop character (which can be a whitespace)stopChar2- the second character (which can be a whitespace)- Returns:
- the first non-whitespace character (or delimiter) found in the input.
-
currentParsedContentLength
int currentParsedContentLength()
Returns the length of the character sequence parsed to produce the current record.- Returns:
- the length of the text content parsed for the current input record
-
currentParsedContent
java.lang.String currentParsedContent()
Returns a String with the input character sequence parsed to produce the current record.- Returns:
- the text content parsed for the current input record.
-
lastIndexOf
int lastIndexOf(char ch)
Returns the last index of a given character in the current parsed content- Parameters:
ch- the character to look for- Returns:
- the last position of the given character in the current parsed content, or
-1if not found.
-
markRecordStart
void markRecordStart()
Marks the start of a new record in the input, used internally to calculate the result ofcurrentParsedContent()
-
getString
java.lang.String getString(char ch, char stop, boolean trim, java.lang.String nullValue, int maxLength)Attempts to collect aStringfrom the current position until a stop character is found on the input, or a line ending is reached. If theStringcan 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 returnnulland the current position of the buffer will remain unchanged.- Parameters:
ch- the current character to be considered. If equal to the stop character thenullValuewill 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 is0.maxLength- the maximum length of theStringto be returned. If the length exceeds this limit,nullwill be returned- Returns:
- the
Stringfound on the input, ornullif the buffer needs to reloaded or the maximum length has been exceeded.
-
skipString
boolean skipString(char ch, char stop)Attempts to skip aStringfrom the current position until a stop character is found on the input, or a line ending is reached. If theStringcan 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 returnfalseand the current position of the buffer will remain unchanged.- Parameters:
ch- the current character to be considered. If equal to the stop characterfalsewill be returnedstop- the stop character that identifies the end of the content to be collected- Returns:
trueif an entireStringvalue was found on the input and skipped, orfalseif the buffer needs to reloaded.
-
getQuotedString
java.lang.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 quotedStringfrom the current position until a closing quote or stop character is found on the input, or a line ending is reached. If theStringcan 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 returnnulland the current position of the buffer will remain unchanged.- Parameters:
quote- the quote characterescape- the quote escape characterescapeEscape- the escape of the quote escape charactermaxLength- the maximum length of theStringto be returned. If the length exceeds this limit,nullwill be returnedstop1- the first stop character that identifies the end of the content to be collectedstop2- the second stop character that identifies the end of the content to be collectedkeepQuotes- flag to indicate the quotes that wrap the resultingStringshould be kept.keepEscape- flag to indicate that escape sequences should be kepttrimLeading- flag to indicate leading whitespaces should be trimmedtrimTrailing- flag to indicate that trailing whitespaces should be trimmed- Returns:
- the
Stringfound on the input, ornullif the buffer needs to reloaded or the maximum length has been exceeded.
-
skipQuotedString
boolean skipQuotedString(char quote, char escape, char stop1, char stop2)Attempts to skip a quotedStringfrom the current position until a stop character is found on the input, or a line ending is reached. If theStringcan 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 returnfalseand the current position of the buffer will remain unchanged.- Parameters:
quote- the quote characterescape- the quote escape characterstop1- the first stop character that identifies the end of the content to be collectedstop2- the second stop character that identifies the end of the content to be collected- Returns:
trueif an entireStringvalue was found on the input and skipped, orfalseif the buffer needs to reloaded.
-
-