Interface ExportFileWriter<C extends ExportFileWriteContext>

All Known Implementing Classes:
CSVExportFileWriter

public interface ExportFileWriter<C extends ExportFileWriteContext>
Responsible for writing the headers and rows of an export to a file. Different file formats and types will require different implementations of this.

Generally speaking, there should be one ExportFileWriter for each Export.fileType that needs to be supported.

The ExportManager will use only the first ExportFileWriter for which canHandle(Export) returns true.

Author:
Samarth Dhruva (samarthd)
  • Method Details

    • canHandle

      boolean canHandle(Export export)
      Returns whether the writer can support writing the file for the given export. Generally this should be entirely based on Export.fileType.
      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

      String getFileExtension()
      Returns the file extension that should be used for the export file that the writer will be writing to.
      Returns:
      the file extension (including the ".") that should be used for the export file
    • createExecutionContext

      C createExecutionContext(OutputStream outputStream)
      Creates a new instance of an ExportFileWriteContext for writing to the given outputStream.
      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

      ExportFileWriteResponse writeHeaders(LinkedHashSet<String> headers, C executionContext)
      Writes the given headers to the output file. The ExportFileWriteContext.outputStream should be left open for further writes.
      Parameters:
      headers - the headers that need to be written to the export file
      executionContext - state information for the particular export being written
      Returns:
      a response describing whether the write operation succeeded or failed
    • writeRows

      ExportFileWriteResponse writeRows(List<Map<String,String>> rows, C executionContext)
      Writes the given rows to the export file. The ExportFileWriteContext.outputStream should be left open for further writes.
      Parameters:
      rows - the rows that need to be written to the export file
      executionContext - state information for the particular export being written
      Returns:
      a response describing whether the write operation succeeded or failed