Class ExporterCSV
java.lang.Object
com.helger.photon.exchange.bulkexport.format.ExporterCSV
- All Implemented Interfaces:
IExporter,IExporterFile
Implementation of
IExporterFile for CSV files.- Author:
- Philip Helger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected com.helger.commons.csv.CSVWriterCreate a new CSV writer.com.helger.commons.state.ESuccessexportRecords(IExportRecordProvider aProvider, OutputStream aOS) Export all provided records to an output stream.final Charsetfinal charfinal EExchangeFileTypefinal Stringfinal charfinal charfinal com.helger.commons.charset.EUnicodeBOMfinal booleanfinal booleanfinal ExporterCSVsetAvoidFinalLineEnd(boolean bAvoidFinalLineEnd) Set whether the CSV file should end with a new line or not.final ExporterCSVsetAvoidWriteEmpty(boolean bAvoidWriteEmpty) Enable or disable that empty files are written.final ExporterCSVsetCharset(Charset aCharset) final ExporterCSVsetEscapeChar(char cEscape) final ExporterCSVsetLineEnd(String sLineEnd) final ExporterCSVsetQuoteChar(char cQuote) final ExporterCSVsetSeparatorChar(char cSeparator) final ExporterCSVsetUnicodeBOM(com.helger.commons.charset.EUnicodeBOM eBOM)
-
Constructor Details
-
ExporterCSV
public ExporterCSV() -
ExporterCSV
-
-
Method Details
-
getFileType
- Specified by:
getFileTypein interfaceIExporterFile- Returns:
- The file type for export.
-
getCharset
-
setCharset
-
getSeparatorChar
public final char getSeparatorChar()- Returns:
- Current separator char
-
setSeparatorChar
- Parameters:
cSeparator- Separator char- Returns:
- this for chaining
-
getQuoteChar
public final char getQuoteChar() -
setQuoteChar
-
getEscapeChar
public final char getEscapeChar() -
setEscapeChar
-
getLineEnd
-
setLineEnd
-
getUnicodeBOM
-
setUnicodeBOM
@Nonnull public final ExporterCSV setUnicodeBOM(@Nullable com.helger.commons.charset.EUnicodeBOM eBOM) -
isAvoidWriteEmpty
public final boolean isAvoidWriteEmpty()- Returns:
trueif empty files are not written,falseotherwise (by default).
-
setAvoidWriteEmpty
Enable or disable that empty files are written. By enabling this, all records are collected which results in higher memory consumption but safer output. If this is disabled (the default) than it my happen that nothing is written on the output stream.- Parameters:
bAvoidWriteEmpty-trueto collect before write,falseto write directly- Returns:
- this for chaining
- Since:
- 7.0.4
-
isAvoidFinalLineEnd
public final boolean isAvoidFinalLineEnd()- Returns:
trueif the written data should end with a line end,falseotherwise (by default).- Since:
- 7.1.1
-
setAvoidFinalLineEnd
Set whether the CSV file should end with a new line or not.- Parameters:
bAvoidFinalLineEnd-trueto avoid the CSV file ending with a new line.- Returns:
- this for chaining
- Since:
- 7.1.1
-
createCSVWriter
@Nonnull @OverrideOnDemand @WillCloseWhenClosed protected com.helger.commons.csv.CSVWriter createCSVWriter(@Nonnull OutputStream aOS) Create a new CSV writer.- Parameters:
aOS- The output stream to write to. May not benull.- Returns:
- The
CSVWriterto used. Nevernull.
-
exportRecords
@Nonnull public com.helger.commons.state.ESuccess exportRecords(@Nonnull IExportRecordProvider aProvider, @Nonnull @WillClose OutputStream aOS) Description copied from interface:IExporterExport all provided records to an output stream.- Specified by:
exportRecordsin interfaceIExporter- Parameters:
aProvider- The provider for all records. May not benull.aOS- The output stream to write to. Will be closed automatically in any case. May not benull.- Returns:
ESuccess.SUCCESSif at lease one record was provided and saving was successful.
-