Package org.supercsv.io
Class Tokenizer
java.lang.Object
org.supercsv.io.AbstractTokenizer
org.supercsv.io.Tokenizer
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ITokenizer
Reads the CSV file, line by line. If you want the line-reading functionality of this class, but want to define your
own implementation of
readColumns(List)
, then consider writing your own Tokenizer by extending
AbstractTokenizer.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enum
Enumeration of tokenizer states. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CommentMatcher
private final StringBuilder
private final StringBuilder
private final int
private final boolean
private final int
private static final char
private final int
private static final char
private final boolean
-
Constructor Summary
ConstructorsConstructorDescriptionTokenizer
(Reader reader, CsvPreference preferences) Constructs a new Tokenizer, which reads the CSV file, line by line. -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
appendSpaces
(StringBuilder sb, int spaces) Appends the required number of spaces to the StringBuilder.Returns the raw (untokenized) CSV row that was just read (which can potentially span multiple lines in the file).boolean
readColumns
(List<String> columns) Reads a CSV row into the supplied List of columns (which can potentially span multiple lines in the file).Methods inherited from class org.supercsv.io.AbstractTokenizer
close, getLineNumber, getPreferences, readLine
-
Field Details
-
NEWLINE
private static final char NEWLINE- See Also:
-
SPACE
private static final char SPACE- See Also:
-
currentColumn
-
currentRow
-
quoteChar
private final int quoteChar -
delimeterChar
private final int delimeterChar -
surroundingSpacesNeedQuotes
private final boolean surroundingSpacesNeedQuotes -
ignoreEmptyLines
private final boolean ignoreEmptyLines -
commentMatcher
-
maxLinesPerRow
private final int maxLinesPerRow
-
-
Constructor Details
-
Tokenizer
Constructs a new Tokenizer, which reads the CSV file, line by line.- Parameters:
reader
- the readerpreferences
- the CSV preferences- Throws:
NullPointerException
- if reader or preferences is null
-
-
Method Details
-
readColumns
Reads a CSV row into the supplied List of columns (which can potentially span multiple lines in the file). The columns list is cleared as the first operation in the method. Any empty columns ("") will be added to the list as null.- Parameters:
columns
- the List of columns to read into- Returns:
- true if something was read, or false if EOF
- Throws:
IOException
- when an IOException occurs
-
appendSpaces
Appends the required number of spaces to the StringBuilder.- Parameters:
sb
- the StringBuilderspaces
- the required number of spaces to append
-
getUntokenizedRow
Returns the raw (untokenized) CSV row that was just read (which can potentially span multiple lines in the file).- Returns:
- the raw (untokenized) CSV row that was just read
-