public abstract class AbstractCsvWriter extends Object implements ICsvWriter
Constructor and Description |
---|
AbstractCsvWriter(Writer writer,
CsvPreference preference)
Constructs a new AbstractCsvWriter with the supplied writer and preferences.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the underlying writer, flushing it first.
|
protected String |
escapeString(String csvElement)
Make a string ready for writing by escaping various characters as specified by the CSV format.
|
void |
flush()
Flushes the underlying writer.
|
int |
getLineNumber()
Gets the current position in the file.
|
int |
getRowNumber()
Gets the current row number (i.e.
|
protected void |
incrementRowAndLineNo()
In order to maintain the current row and line numbers, this method must be called at the very
beginning of every write method implemented in concrete CSV writers.
|
void |
writeHeader(String... header)
Writes the header of the CSV file.
|
protected void |
writeRow(List<?> columns)
Writes a List of columns as a line to the CsvWriter.
|
protected void |
writeRow(Object... columns)
Writes one or more Object columns as a line to the CsvWriter.
|
protected void |
writeRow(String... columns)
Writes one or more String columns as a line to the CsvWriter.
|
public AbstractCsvWriter(Writer writer, CsvPreference preference)
writer
- the stream to write topreference
- the CSV preferencesNullPointerException
- if writer or preference are nullpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void flush() throws IOException
flush
in interface Flushable
IOException
protected String escapeString(String csvElement)
csvElement
- an element of a CSV fileprotected void incrementRowAndLineNo()
getLineNumber()
and getRowNumber()
can be called after writing to return the line/row just
written.public int getLineNumber()
getLineNumber
in interface ICsvWriter
public int getRowNumber()
getRowNumber
in interface ICsvWriter
protected void writeRow(List<?> columns) throws IOException
columns
- the columns to writeIllegalArgumentException
- if columns.size == 0IOException
- If an I/O error occursNullPointerException
- if columns is nullprotected void writeRow(Object... columns) throws IOException
columns
- the columns to writeIllegalArgumentException
- if columns.length == 0IOException
- If an I/O error occursNullPointerException
- if columns is nullprotected void writeRow(String... columns) throws IOException
columns
- the columns to writeIllegalArgumentException
- if columns.length == 0IOException
- If an I/O error occursNullPointerException
- if columns is nullpublic void writeHeader(String... header) throws IOException
writeHeader
in interface ICsvWriter
header
- one or more header StringsIOException
- if an I/O error occursCopyright © 2007-2012 Super CSV. All Rights Reserved.