Class ExporterCSV
- java.lang.Object
-
- com.helger.photon.exchange.bulkexport.format.ExporterCSV
-
- All Implemented Interfaces:
IExporter,IExporterFile
@NotThreadSafe public class ExporterCSV extends Object implements IExporterFile
Implementation ofIExporterFilefor CSV files.- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Constructor Description ExporterCSV()ExporterCSV(Charset aCharset)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected com.helger.commons.csv.CSVWritercreateCSVWriter(OutputStream aOS)Create a new CSV writer.com.helger.commons.state.ESuccessexportRecords(IExportRecordProvider aProvider, OutputStream aOS)Export all provided records to an output stream.CharsetgetCharset()chargetEscapeChar()EExchangeFileTypegetFileType()StringgetLineEnd()chargetQuoteChar()chargetSeparatorChar()com.helger.commons.charset.EUnicodeBOMgetUnicodeBOM()booleanisAvoidFinalLineEnd()booleanisAvoidWriteEmpty()ExporterCSVsetAvoidFinalLineEnd(boolean bAvoidFinalLineEnd)Set whether the CSV file should end with a new line or not.ExporterCSVsetAvoidWriteEmpty(boolean bAvoidWriteEmpty)Enable or disable that empty files are written.ExporterCSVsetCharset(Charset aCharset)ExporterCSVsetEscapeChar(char cEscape)ExporterCSVsetLineEnd(String sLineEnd)ExporterCSVsetQuoteChar(char cQuote)ExporterCSVsetSeparatorChar(char cSeparator)ExporterCSVsetUnicodeBOM(com.helger.commons.charset.EUnicodeBOM eBOM)
-
-
-
Method Detail
-
getFileType
@Nonnull public final EExchangeFileType getFileType()
- Specified by:
getFileTypein interfaceIExporterFile- Returns:
- The file type for export.
-
setCharset
@Nonnull public final ExporterCSV setCharset(@Nonnull Charset aCharset)
-
getSeparatorChar
public final char getSeparatorChar()
- Returns:
- Current separator char
-
setSeparatorChar
@Nonnull public final ExporterCSV setSeparatorChar(char cSeparator)
- Parameters:
cSeparator- Separator char- Returns:
- this for chaining
-
getQuoteChar
public final char getQuoteChar()
-
setQuoteChar
@Nonnull public final ExporterCSV setQuoteChar(char cQuote)
-
getEscapeChar
public final char getEscapeChar()
-
setEscapeChar
@Nonnull public final ExporterCSV setEscapeChar(char cEscape)
-
setLineEnd
@Nonnull public final ExporterCSV setLineEnd(@Nonnull @Nonempty String sLineEnd)
-
getUnicodeBOM
@Nullable public final com.helger.commons.charset.EUnicodeBOM 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
@Nonnull public final ExporterCSV setAvoidWriteEmpty(boolean bAvoidWriteEmpty)
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
@Nonnull public final ExporterCSV setAvoidFinalLineEnd(boolean bAvoidFinalLineEnd)
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.
-
-