Closeable
, AutoCloseable
, Iterable<String[]>
public class CsvReader extends Object implements Closeable, Iterable<String[]>
CsvReader r;
while (r.next()) {
String value1 = r.getString(1);
// ...
}
Constructor | Description |
---|---|
CsvReader(Reader r) |
Creates a "standard" CSV reader (separator is comma and quoted mode active)
|
CsvReader(Reader r,
char sep,
boolean quoted) |
Returns a new CSV scanner to read from `r`.
|
Modifier and Type | Method | Description |
---|---|---|
void |
close() |
|
int |
findColumn(String columnLabel) |
|
byte |
getByte(int columnIndex) |
|
byte |
getByte(String columnLabel) |
|
int |
getColumnCount() |
|
String |
getColumnLabel(int columnIndex) |
|
double |
getDouble(int columnIndex) |
|
double |
getDouble(String columnLabel) |
|
float |
getFloat(int columnIndex) |
|
float |
getFloat(String columnLabel) |
|
int |
getInt(int columnIndex) |
|
int |
getInt(String columnLabel) |
|
long |
getLong(int columnIndex) |
|
long |
getLong(String columnLabel) |
|
<T> T |
getObject(int columnIndex,
Class<T> type) |
|
<T> T |
getObject(String columnLabel,
Class<T> type) |
|
int |
getRow() |
Returns current line number.
|
short |
getShort(int columnIndex) |
|
short |
getShort(String columnLabel) |
|
String |
getString(int columnIndex) |
|
String |
getString(String columnLabel) |
|
Iterator<String[]> |
iterator() |
Iterates on rows.
|
boolean |
next() |
|
void |
reset(Reader r) |
Reuse this component with a new content.
|
Map<String,Integer> |
scanHeaders(boolean ignoreCommentMarker) |
|
void |
setCommentMarker(char comment) |
Sets the character marking the start of a line comment.
|
void |
setEmptyIsNull(boolean emptyIsNull) |
Treats empty value as `null` value
|
void |
setSkipEmptyLines(boolean skipEmptyLines) |
|
void |
setTrim(boolean trim) |
Trims spaces (only on not-quoted values).
|
void |
setUnmarshaler(Unmarshaler unmarshaler) |
Sets the component used by
getObject(int, java.lang.Class<T>) to transform text to object. |
void |
skipRows(int n) |
Skips `n` rows
|
Stream<String[]> |
stream() |
|
String[] |
values() |
|
boolean |
wasNull() |
Reports whether the last column read had an empty value.
|
void |
withHeaders(Iterable<String> headers) |
forEach, spliterator
public CsvReader(@WillCloseWhenClosed @Nonnull Reader r)
public CsvReader(@WillCloseWhenClosed @Nonnull Reader r, char sep, boolean quoted)
public final void reset(@WillCloseWhenClosed @Nonnull Reader r) throws IOException
IOException
@Nonnull public Map<String,Integer> scanHeaders(boolean ignoreCommentMarker) throws IOException
IOException
public boolean next() throws IOException
IOException
ResultSet.next()
@Nullable public String getString(@Nonnegative int columnIndex) throws ScanException
columnIndex
- the first column is 1, the second is 2, ...ScanException
ResultSet.getString(int)
public String getString(String columnLabel) throws ScanException
ScanException
ResultSet.getString(String)
public byte getByte(@Nonnegative int columnIndex) throws ScanException
columnIndex
- the first column is 1, the second is 2, ...ScanException
ResultSet.getByte(int)
public byte getByte(String columnLabel) throws ScanException
ScanException
ResultSet.getByte(String)
public short getShort(@Nonnegative int columnIndex) throws ScanException
columnIndex
- the first column is 1, the second is 2, ...ScanException
ResultSet.getShort(int)
public short getShort(String columnLabel) throws ScanException
ScanException
ResultSet.getShort(String)
public int getInt(@Nonnegative int columnIndex) throws ScanException
columnIndex
- the first column is 1, the second is 2, ...ScanException
ResultSet.getInt(int)
public int getInt(String columnLabel) throws ScanException
ScanException
ResultSet.getInt(String)
public long getLong(@Nonnegative int columnIndex) throws ScanException
columnIndex
- the first column is 1, the second is 2, ...ScanException
ResultSet.getLong(int)
public long getLong(String columnLabel) throws ScanException
ScanException
ResultSet.getLong(String)
public float getFloat(@Nonnegative int columnIndex) throws ScanException
columnIndex
- the first column is 1, the second is 2, ...ScanException
ResultSet.getFloat(int)
public float getFloat(String columnLabel) throws ScanException
ScanException
ResultSet.getFloat(String)
public double getDouble(@Nonnegative int columnIndex) throws ScanException
columnIndex
- the first column is 1, the second is 2, ...ScanException
ResultSet.getDouble(int)
public double getDouble(String columnLabel) throws ScanException
ScanException
ResultSet.getDouble(String)
public <T> T getObject(@Nonnegative int columnIndex, Class<T> type) throws ScanException
columnIndex
- the first column is 1, the second is 2, ...ScanException
ResultSet.getObject(int, Class)
public <T> T getObject(String columnLabel, Class<T> type) throws ScanException
ScanException
ResultSet.getObject(String, Class)
public int findColumn(String columnLabel) throws ScanException
ScanException
ResultSet.findColumn(String)
public void skipRows(@Nonnegative int n) throws IOException
IOException
@Nonnegative public int getRow()
ResultSet.getRow()
@Nonnegative public int getColumnCount()
ResultSetMetaData.getColumnCount()
public String getColumnLabel(@Nonnegative int columnIndex) throws ScanException
columnIndex
- the first column is 1, the second is 2, ...ScanException
ResultSetMetaData.getColumnLabel(int)
public void setCommentMarker(char comment)
public void setTrim(boolean trim)
public void setSkipEmptyLines(boolean skipEmptyLines)
public void setEmptyIsNull(boolean emptyIsNull)
public boolean wasNull()
ResultSet.wasNull()
public void setUnmarshaler(@Nullable Unmarshaler unmarshaler)
getObject(int, java.lang.Class<T>)
to transform text to object.public void close() throws IOException
close
in interface AutoCloseable
close
in interface Closeable
IOException
@Nonnull public Iterator<String[]> iterator()
CsvReader r;
for (String[] row : r) {
// ...
}
iterator
in interface Iterable<String[]>
IllegalStateException
- for IOException.Copyright © 2018. All rights reserved.