Package org.supercsv.io
Class Tokenizer
- java.lang.Object
-
- org.supercsv.io.AbstractTokenizer
-
- org.supercsv.io.Tokenizer
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,ITokenizer
public class Tokenizer extends AbstractTokenizer
Reads the CSV file, line by line. If you want the line-reading functionality of this class, but want to define your own implementation ofreadColumns(List)
, then consider writing your own Tokenizer by extending AbstractTokenizer.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Tokenizer.TokenizerState
Enumeration of tokenizer states.
-
Field Summary
Fields Modifier and Type Field Description private CommentMatcher
commentMatcher
private java.lang.StringBuilder
currentColumn
private java.lang.StringBuilder
currentRow
private int
delimeterChar
private boolean
ignoreEmptyLines
private int
maxLinesPerRow
private static char
NEWLINE
private int
quoteChar
private static char
SPACE
private boolean
surroundingSpacesNeedQuotes
-
Constructor Summary
Constructors Constructor Description Tokenizer(java.io.Reader reader, CsvPreference preferences)
Constructs a new Tokenizer, which reads the CSV file, line by line.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
appendSpaces(java.lang.StringBuilder sb, int spaces)
Appends the required number of spaces to the StringBuilder.java.lang.String
getUntokenizedRow()
Returns the raw (untokenized) CSV row that was just read (which can potentially span multiple lines in the file).boolean
readColumns(java.util.List<java.lang.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 Detail
-
NEWLINE
private static final char NEWLINE
- See Also:
- Constant Field Values
-
SPACE
private static final char SPACE
- See Also:
- Constant Field Values
-
currentColumn
private final java.lang.StringBuilder currentColumn
-
currentRow
private final java.lang.StringBuilder currentRow
-
quoteChar
private final int quoteChar
-
delimeterChar
private final int delimeterChar
-
surroundingSpacesNeedQuotes
private final boolean surroundingSpacesNeedQuotes
-
ignoreEmptyLines
private final boolean ignoreEmptyLines
-
commentMatcher
private final CommentMatcher commentMatcher
-
maxLinesPerRow
private final int maxLinesPerRow
-
-
Constructor Detail
-
Tokenizer
public Tokenizer(java.io.Reader reader, CsvPreference preferences)
Constructs a new Tokenizer, which reads the CSV file, line by line.- Parameters:
reader
- the readerpreferences
- the CSV preferences- Throws:
java.lang.NullPointerException
- if reader or preferences is null
-
-
Method Detail
-
readColumns
public boolean readColumns(java.util.List<java.lang.String> columns) throws java.io.IOException
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:
java.io.IOException
- when an IOException occurs
-
appendSpaces
private static void appendSpaces(java.lang.StringBuilder sb, int spaces)
Appends the required number of spaces to the StringBuilder.- Parameters:
sb
- the StringBuilderspaces
- the required number of spaces to append
-
getUntokenizedRow
public java.lang.String 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
-
-