Class CsvHandler

All Implemented Interfaces:
FileHandler, AutoCloseable

public final class CsvHandler extends TempResourceContainer implements FileHandler
Handles the output stage of a CSV export.

This class holds a temporary CSV file and writes its content to a provided OutputStream. It ensures the file is only consumed once, and automatically cleans up temporary files afterward.

Since:
2025-07-19
  • Method Details

    • writeTo

      public void writeTo(OutputStream outputStream)
      Writes the content of the CSV file to the given OutputStream.

      This method can be called only once. Subsequent calls will throw CsvWriteException.

      The temporary file and directory will be deleted automatically after writing.

      Note: I/O errors are wrapped as CsvWriteException (unchecked) rather than propagated as IOException, so callers do not need a try-catch for checked exceptions.

      Specified by:
      writeTo in interface FileHandler
      Parameters:
      outputStream - The stream to which the CSV content will be written
      Throws:
      CsvWriteException - If this method has already been called or if an I/O error occurs