Closeable
, AutoCloseable
, CharSequence
, Iterable<String>
public class CsvScanner extends AbstractCsvScanner<String> implements Iterable<String>
CsvScanner s;
while (s.scan())) {
String value = s.value();
// ...
if (s.atEndOfRow()) {
// ...
}
}
Constructor | Description |
---|---|
CsvScanner(Reader r) |
Creates a "standard" CSV reader (separator is comma and quoted mode active)
|
CsvScanner(Reader r,
char sep,
boolean quoted) |
Returns a new CSV scanner to read from `r`.
|
Modifier and Type | Method | Description |
---|---|---|
Iterator<String> |
iterator() |
Iterates on fields.
|
protected String |
newToken(char[] data,
int start,
int end) |
|
boolean |
scanBool(String trueValue) |
Reads bool until next separator or eol/eof.
|
char |
scanChar() |
Reads char until next separator or eol/eof.
|
double |
scanDouble() |
Reads double until next separator or eol/eof.
|
float |
scanFloat() |
Reads float until next separator or eol/eof.
|
int |
scanInt() |
Reads int until next separator or eol/eof.
|
long |
scanLong() |
Reads long until next separator or eol/eof.
|
int |
scanRow(String[] values) |
Extra fields are skipped (when the number of fields is greater than `values` size).
|
String |
scanText() |
Reads text until next separator or eol/eof.
|
String |
value() |
Returns the most recent value generated by a call to scan.
|
atEndOfRow, column, init, lineno, reset, setCommentMarker, setSkipEmptyLines, setTrim, skipRows
chars, codePoints
forEach, spliterator
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
advance, atEndOfFile, charAt, close, length, peek, position, scan, setSplitFunc, subSequence, token, toString
public CsvScanner(@WillCloseWhenClosed @Nonnull Reader r)
public CsvScanner(@WillCloseWhenClosed @Nonnull Reader r, char sep, boolean quoted)
protected String newToken(@Nonnull char[] data, @Nonnegative int start, @Nonnegative int end)
newToken
in class AbstractCsvScanner<String>
@Nonnegative public int scanRow(@Nonnull String[] values) throws IOException
AbstractCsvScanner.column
).
At EOF, returns 0.
CsvScanner s;
String[] values = new String[20]; // max columns
int n;
while ((n = s.scanRow(values)) > 0) {
String[] row = Arrays.copyOf(values, n);
// ...
}
IOException
public String value()
@Nullable public String scanText() throws IOException
IOException
public double scanDouble() throws IOException, NumberFormatException
IOException
NumberFormatException
public float scanFloat() throws IOException, NumberFormatException
IOException
NumberFormatException
public int scanInt() throws IOException, NumberFormatException
IOException
NumberFormatException
public long scanLong() throws IOException, NumberFormatException
IOException
NumberFormatException
public boolean scanBool(@Nonnull String trueValue) throws IOException
IOException
public char scanChar() throws IOException, IllegalArgumentException
IOException
IllegalArgumentException
@Nonnull public Iterator<String> iterator()
CsvScanner s;
while (!s.atEndOfFile())) {
for (String field : s) {
// ...
}
}
iterator
in interface Iterable<String>
IllegalStateException
- for IOException.Copyright © 2018. All rights reserved.