Class CSVExportFileWriter
java.lang.Object
com.broadleafcommerce.common.dataexport.service.CSVExportFileWriter
- All Implemented Interfaces:
ExportFileWriter<CSVExportFileWriteContext>
public class CSVExportFileWriter
extends Object
implements ExportFileWriter<CSVExportFileWriteContext>
An implementation of
ExportFileWriter
that can write CSV files.- Author:
- Samarth Dhruva (samarthd)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether the writer can support writing the file for the given export.createExecutionContext
(OutputStream outputStream) Creates a new instance of anExportFileWriteContext
for writing to the givenoutputStream
.Returns the file extension that should be used for the export file that the writer will be writing to.writeHeaders
(LinkedHashSet<String> headers, CSVExportFileWriteContext executionContext) Writes the given headers to the output file.Writes the given rows to the export file.
-
Constructor Details
-
CSVExportFileWriter
public CSVExportFileWriter()
-
-
Method Details
-
canHandle
Description copied from interface:ExportFileWriter
Returns whether the writer can support writing the file for the given export. Generally this should be entirely based onExport.fileType
.- Specified by:
canHandle
in interfaceExportFileWriter<CSVExportFileWriteContext>
- Parameters:
export
- details about the export that will be processed- Returns:
- true if the file writer can support writing the file for the given export, false otherwise
-
getFileExtension
Description copied from interface:ExportFileWriter
Returns the file extension that should be used for the export file that the writer will be writing to.- Specified by:
getFileExtension
in interfaceExportFileWriter<CSVExportFileWriteContext>
- Returns:
- the file extension (including the ".") that should be used for the export file
-
createExecutionContext
Description copied from interface:ExportFileWriter
Creates a new instance of anExportFileWriteContext
for writing to the givenoutputStream
.- Specified by:
createExecutionContext
in interfaceExportFileWriter<CSVExportFileWriteContext>
- Parameters:
outputStream
- the output stream that the writer should be writing to- Returns:
- a new instance of a file writing context that is bound to the given output stream
-
writeHeaders
public ExportFileWriteResponse writeHeaders(LinkedHashSet<String> headers, CSVExportFileWriteContext executionContext) Description copied from interface:ExportFileWriter
Writes the given headers to the output file. TheExportFileWriteContext.outputStream
should be left open for further writes.- Specified by:
writeHeaders
in interfaceExportFileWriter<CSVExportFileWriteContext>
- Parameters:
headers
- the headers that need to be written to the export fileexecutionContext
- state information for the particular export being written- Returns:
- a response describing whether the write operation succeeded or failed
-
writeRows
public ExportFileWriteResponse writeRows(List<Map<String, String>> rows, CSVExportFileWriteContext executionContext) Description copied from interface:ExportFileWriter
Writes the given rows to the export file. TheExportFileWriteContext.outputStream
should be left open for further writes.- Specified by:
writeRows
in interfaceExportFileWriter<CSVExportFileWriteContext>
- Parameters:
rows
- the rows that need to be written to the export fileexecutionContext
- state information for the particular export being written- Returns:
- a response describing whether the write operation succeeded or failed
-