Closeable
, Flushable
, AutoCloseable
public class CsvColWriter extends Object implements Closeable, Flushable
CsvColWriter w;
CsvReader r;
w.withColumnIndexes(r.scanHeaders(true));
w.writerHeaders(false);
while (r.next()) {
w.setString(2, r.getString(1));
w.setString(1, r.getString(2));
...
w.endOfRow();
}
w.flush();
Constructor | Description |
---|---|
CsvColWriter(Writer w) |
|
CsvColWriter(Writer w,
char sep,
boolean quoted) |
Modifier and Type | Method | Description |
---|---|---|
void |
close() |
|
void |
endOfRow() |
Tells when a line break must be inserted.
|
int |
findColumn(String columnLabel) |
|
void |
flush() |
|
String |
getColumnLabel(int columnIndex) |
|
void |
setByte(int columnIndex,
byte x) |
|
void |
setByte(String columnLabel,
byte x) |
|
void |
setCommentMarker(char comment) |
Sets the character marking the start of a line comment.
|
void |
setDouble(int columnIndex,
double x) |
|
void |
setDouble(String columnLabel,
double x) |
|
void |
setFloat(int columnIndex,
float x) |
|
void |
setFloat(String columnLabel,
float x) |
|
void |
setInt(int columnIndex,
int x) |
|
void |
setInt(String columnLabel,
int x) |
|
void |
setLong(int columnIndex,
long x) |
|
void |
setLong(String columnLabel,
long x) |
|
void |
setMarshaler(Marshaler marshaler) |
Sets the component called by
setObject(int, java.lang.Object) to marshall value to text. |
void |
setObject(int columnIndex,
Object x) |
|
void |
setObject(String columnLabel,
Object x) |
|
void |
setShort(int columnIndex,
short x) |
|
void |
setShort(String columnLabel,
short x) |
|
void |
setString(int columnIndex,
String x) |
|
void |
setString(String columnLabel,
String x) |
|
void |
useCRLF() |
Use \r\n as the line terminator.
|
void |
withHeaders(Collection<String> headers) |
|
void |
writerHeaders(boolean useCommentMarker) |
public CsvColWriter(@WillCloseWhenClosed @Nonnull Writer w)
public CsvColWriter(@WillCloseWhenClosed @Nonnull Writer w, char sep, boolean quoted)
public void withHeaders(@Nonnull Collection<String> headers)
@Nonnegative public int findColumn(String columnLabel) throws IllegalStateException
IllegalStateException
ResultSet.findColumn(String)
public String getColumnLabel(@Nonnegative int columnIndex) throws ScanException
ScanException
public void writerHeaders(boolean useCommentMarker) throws IOException
IllegalStateException
- if no header has been specified (withHeaders(java.util.Collection<java.lang.String>)
).IOException
public void setString(@Nonnegative int columnIndex, String x)
columnIndex
- the first column is 1, the second is 2, ...x
- the column valuepublic void setByte(int columnIndex, byte x)
columnIndex
- the first column is 1, the second is 2, ...x
- the column valuepublic void setByte(String columnLabel, byte x)
public void setShort(int columnIndex, short x)
columnIndex
- the first column is 1, the second is 2, ...x
- the column valuepublic void setShort(String columnLabel, short x)
public void setInt(int columnIndex, int x)
columnIndex
- the first column is 1, the second is 2, ...x
- the column valuepublic void setInt(String columnLabel, int x)
public void setLong(int columnIndex, long x)
columnIndex
- the first column is 1, the second is 2, ...x
- the column valuepublic void setLong(String columnLabel, long x)
public void setFloat(int columnIndex, float x)
columnIndex
- the first column is 1, the second is 2, ...x
- the column valuepublic void setFloat(String columnLabel, float x)
public void setDouble(int columnIndex, double x)
columnIndex
- the first column is 1, the second is 2, ...x
- the column valuepublic void setDouble(String columnLabel, double x)
public void setObject(@Nonnegative int columnIndex, @Nullable Object x)
columnIndex
- the first column is 1, the second is 2, ...x
- the column valuepublic void endOfRow() throws IOException
IOException
public void useCRLF()
public void setCommentMarker(char comment)
public void setMarshaler(@Nullable Marshaler marshaler)
setObject(int, java.lang.Object)
to marshall value to text.public void close() throws IOException
close
in interface AutoCloseable
close
in interface Closeable
IOException
public void flush() throws IOException
flush
in interface Flushable
IOException
Copyright © 2018. All rights reserved.