public abstract class AbstractCsvWriter extends java.lang.Object implements ICsvWriter
Constructor and Description |
---|
AbstractCsvWriter(java.io.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 java.lang.String |
escapeString(java.lang.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(java.lang.String... header)
Writes the header of the CSV file.
|
protected void |
writeRow(java.util.List<?> columns)
Writes a List of columns as a line to the CsvWriter.
|
protected void |
writeRow(java.lang.Object... columns)
Writes one or more Object columns as a line to the CsvWriter.
|
protected void |
writeRow(java.lang.String... columns)
Writes one or more String columns as a line to the CsvWriter.
|
public AbstractCsvWriter(java.io.Writer writer, CsvPreference preference)
writer
- the stream to write topreference
- the CSV preferencesjava.lang.NullPointerException
- if writer or preference are nullpublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
java.io.IOException
protected java.lang.String escapeString(java.lang.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(java.util.List<?> columns) throws java.io.IOException
columns
- the columns to writejava.lang.IllegalArgumentException
- if columns.size == 0java.io.IOException
- If an I/O error occursjava.lang.NullPointerException
- if columns is nullprotected void writeRow(java.lang.Object... columns) throws java.io.IOException
columns
- the columns to writejava.lang.IllegalArgumentException
- if columns.length == 0java.io.IOException
- If an I/O error occursjava.lang.NullPointerException
- if columns is nullprotected void writeRow(java.lang.String... columns) throws java.io.IOException
columns
- the columns to writejava.lang.IllegalArgumentException
- if columns.length == 0java.io.IOException
- If an I/O error occursjava.lang.NullPointerException
- if columns is nullpublic void writeHeader(java.lang.String... header) throws java.io.IOException
writeHeader
in interface ICsvWriter
header
- one or more header Stringsjava.io.IOException
- if an I/O error occursCopyright © 2007-2012 Super CSV. All Rights Reserved.