public class CSVWriter extends AbstractDataWriter
Class that writes all values of a DataSource
to a character
separated file. The file then stores the values separated by a certain
delimiter character. The delimiter is chosen based on the file type but can
also be set manually. By default the comma character will be used as a
delimiter for separating columns. Lines end with a carriage return and a
line feed character.
CSVWriter
instances should be obtained by the
DataWriterFactory
rather than being created manually:
DataWriterFactory factory = DataWriterFactory.getInstance(); DataWriter writer = factory.get("text/csv"); writer.write(data, new FileOutputStream(filename));
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SEPARATOR_CHAR
Key for specifying a
Character value that defines the
delimiting character used to separate columns. |
Constructor and Description |
---|
CSVWriter(java.lang.String mimeType)
Creates a new instance with the specified MIME-Type.
|
Modifier and Type | Method and Description |
---|---|
void |
write(DataSource data,
java.io.OutputStream output)
Stores the specified data source.
|
getMimeType, getSetting, setDefault, setSetting
addCapabilities, getCapabilities
public static final java.lang.String SEPARATOR_CHAR
Character
value that defines the
delimiting character used to separate columns.public CSVWriter(java.lang.String mimeType)
mimeType
- MIME-Type of the output file.public void write(DataSource data, java.io.OutputStream output) throws java.io.IOException
data
- DataSource to be stored.output
- OutputStream to be written to.java.io.IOException
- if writing the data failed