final class Lexer
extends java.lang.Object
implements java.io.Closeable
| Modifier and Type | Field and Description |
|---|---|
private char |
commentStart |
private static java.lang.String |
CR_STRING |
private char |
delimiter |
private static char |
DISABLED
Constant char to use for disabling comments, escapes and encapsulation.
|
private char |
escape |
private java.lang.String |
firstEol |
private boolean |
ignoreEmptyLines |
private boolean |
ignoreSurroundingSpaces |
private static java.lang.String |
LF_STRING |
private char |
quoteChar |
private ExtendedBufferedReader |
reader
The input stream
|
| Constructor and Description |
|---|
Lexer(CSVFormat format,
ExtendedBufferedReader reader) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes resources.
|
(package private) long |
getCharacterPosition()
Returns the current character position
|
(package private) long |
getCurrentLineNumber()
Returns the current line number
|
(package private) java.lang.String |
getFirstEol() |
(package private) boolean |
isClosed() |
(package private) boolean |
isCommentStart(int ch) |
(package private) boolean |
isDelimiter(int ch) |
(package private) boolean |
isEndOfFile(int ch) |
(package private) boolean |
isEscape(int ch) |
private boolean |
isMetaChar(int ch) |
(package private) boolean |
isQuoteChar(int ch) |
(package private) boolean |
isStartOfLine(int ch)
Checks if the current character represents the start of a line: a CR, LF or is at the start of the file.
|
(package private) boolean |
isWhitespace(int ch) |
private char |
mapNullToDisabled(java.lang.Character c) |
(package private) Token |
nextToken(Token token)
Returns the next token.
|
private Token |
parseEncapsulatedToken(Token token)
Parses an encapsulated token.
|
private Token |
parseSimpleToken(Token token,
int ch)
Parses a simple token.
|
(package private) boolean |
readEndOfLine(int ch)
Greedily accepts \n, \r and \r\n This checker consumes silently the second control-character...
|
(package private) int |
readEscape()
Handle an escape sequence.
|
(package private) void |
trimTrailingSpaces(java.lang.StringBuilder buffer) |
private static final java.lang.String CR_STRING
private static final java.lang.String LF_STRING
private static final char DISABLED
FFFE would be encoded as two
chars (using surrogates) and thus there should never be a collision with a real text char.private final char delimiter
private final char escape
private final char quoteChar
private final char commentStart
private final boolean ignoreSurroundingSpaces
private final boolean ignoreEmptyLines
private final ExtendedBufferedReader reader
private java.lang.String firstEol
Lexer(CSVFormat format, ExtendedBufferedReader reader)
java.lang.String getFirstEol()
Token nextToken(Token token) throws java.io.IOException
A token corresponds to a term, a record change or an end-of-file indicator.
token - an existing Token object to reuse. The caller is responsible to initialize the Token.java.io.IOException - on stream access errorprivate Token parseSimpleToken(Token token, int ch) throws java.io.IOException
token - the current tokench - the current characterjava.io.IOException - on stream access errorprivate Token parseEncapsulatedToken(Token token) throws java.io.IOException
token - the current tokenjava.io.IOException - on invalid state: EOF before closing encapsulator or invalid character before delimiter or EOLprivate char mapNullToDisabled(java.lang.Character c)
long getCurrentLineNumber()
long getCharacterPosition()
int readEscape()
throws java.io.IOException
ExtendedBufferedReader.getLastChar()
on the input stream.Constants.END_OF_STREAM if char following the escape is
invalid.java.io.IOException - if there is a problem reading the stream or the end of stream is detected:
the escape character is not allowed at end of stremvoid trimTrailingSpaces(java.lang.StringBuilder buffer)
boolean readEndOfLine(int ch)
throws java.io.IOException
java.io.IOExceptionboolean isClosed()
boolean isWhitespace(int ch)
boolean isStartOfLine(int ch)
ch - the character to checkboolean isEndOfFile(int ch)
boolean isDelimiter(int ch)
boolean isEscape(int ch)
boolean isQuoteChar(int ch)
boolean isCommentStart(int ch)
private boolean isMetaChar(int ch)
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOException - If an I/O error occurs