public class CSVWriter extends AbstractTableWriter
Implementation of TableWriter
for CSV files.
Constructor and Description |
---|
CSVWriter(Writer w,
TableLayout l)
Construct a new CSV writer.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
No-op close implementaiton.
|
TableLayout |
getLayout()
Get the layout of this table.
|
static CSVWriter |
open(File file,
TableLayout layout)
Open a CSV writer to write to an auto-compressed file.
|
static CSVWriter |
open(File file,
TableLayout layout,
CompressionMode compression)
Open a CSV writer to write to a file.
|
void |
writeRow(List<?> row)
Write a row to the table.
|
checkRowWidth, writeRow
public CSVWriter(@WillCloseWhenClosed @Nonnull Writer w, @Nullable TableLayout l) throws IOException
Construct a new CSV writer.
w
- The underlying writer to output to.l
- The table layout, or null
if the table has no headers.IOException
- if there is an error writing the column headers.public void close() throws IOException
AbstractTableWriter
No-op close implementaiton.
close
in interface Closeable
close
in interface AutoCloseable
close
in interface TableWriter
close
in class AbstractTableWriter
IOException
public void writeRow(List<?> row) throws IOException
TableWriter
Write a row to the table. This method is thread-safe.
row
- A row of values. If the table requires more columns, the remaining columns are empty. The row is copied if necessary; the caller is free to re-use the same array for returnValue calls.IOException
- if an error occurs writing the row.public TableLayout getLayout()
TableWriter
Get the layout of this table.
public static CSVWriter open(File file, TableLayout layout, CompressionMode compression) throws IOException
Open a CSV writer to write to a file.
file
- The file to write to.layout
- The layout of the table.compression
- What compression, if any, to use.file
.IOException
- if there is an error opening the file or writing the column header.public static CSVWriter open(File file, @Nullable TableLayout layout) throws IOException
Open a CSV writer to write to an auto-compressed file. The file will be compressed if its name ends in “.gz”.
file
- The file.layout
- The table layout.IOException
- if there is an error opening the file or writing the column header.open(File, TableLayout, CompressionMode)