public class CSVDataExporter extends AbstractDataExporter
IDataExporter
that exports data to a CSV file. This class allows for customization of the exact CSV format, including
setting the delimiter, the text quoting character and the character set.
This class will export CSV files in a format consistent with RFC4180 by default.
Constructor and Description |
---|
CSVDataExporter()
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
<T> void |
exportData(IDataProvider<T> dataProvider,
List<IExportableColumn<T,?>> columns,
OutputStream outputStream)
Exports the data provided by the
IDataProvider to the OutputStream . |
String |
getCharacterSet()
Returns the character set encoding to be used when exporting data.
|
String |
getContentType()
Returns the content type of the exported data.
|
char |
getDelimiter()
Returns the delimiter to be used for separating fields.
|
char |
getQuoteCharacter()
Returns the character to be used for quoting fields.
|
boolean |
isExportHeadersEnabled()
Indicates if header exporting is enabled.
|
protected String |
quoteValue(String value)
Quotes a value for export to CSV.
|
CSVDataExporter |
setCharacterSet(String characterSet)
Sets the character set encoding to be used when exporting data.
|
CSVDataExporter |
setDelimiter(char delimiter)
Sets the delimiter to be used to separate fields.
|
CSVDataExporter |
setExportHeadersEnabled(boolean exportHeadersEnabled)
Turns on or off export headers functionality.
|
CSVDataExporter |
setQuoteCharacter(char quoteCharacter)
Sets the character to be used to quote fields.
|
getDataFormatNameModel, getFileNameExtension, setContentType, setDataFormatNameModel, setFileNameExtension
public CSVDataExporter setDelimiter(char delimiter)
delimiter
- The delimiter to be used to separate fields.this
, for chaining.public char getDelimiter()
public String getCharacterSet()
public CSVDataExporter setCharacterSet(String characterSet)
characterSet
- The character set encoding to be used when exporting data.this
, for chaining.public char getQuoteCharacter()
public CSVDataExporter setQuoteCharacter(char quoteCharacter)
quoteCharacter
- The character to be used to quote fields.this
, for chaining.public String getContentType()
getContentType
in interface IDataExporter
getContentType
in class AbstractDataExporter
public CSVDataExporter setExportHeadersEnabled(boolean exportHeadersEnabled)
true
, then the first
line of the export will contain the column headers. This defaults to true
.exportHeadersEnabled
- A boolean indicating whether or not headers should be exported.this
, for chaining.public boolean isExportHeadersEnabled()
true
.protected String quoteValue(String value)
value
- The value to be quoted.public <T> void exportData(IDataProvider<T> dataProvider, List<IExportableColumn<T,?>> columns, OutputStream outputStream) throws IOException
IDataExporter
IDataProvider
to the OutputStream
.T
- The type of each row of data provided by the IDataProvider
.dataProvider
- The IDataProvider
from which to retrieve the data.columns
- The IExportableColumn
to use to describe the data.outputStream
- The OutputStream
to which to write the exported data.IOException
- If an error occurs.Copyright © 2006–2021 Apache Software Foundation. All rights reserved.