Class CsvReadHandler<T>

Type Parameters:
T - The target row data type
All Implemented Interfaces:
AutoCloseable

public class CsvReadHandler<T> extends AbstractReadHandler<T>
Reads CSV files and maps rows to Java objects.

Resource management

On construction, the handler copies the input stream to a temporary file on disk. These temp resources are released when:
Since:
2025-07-19
  • Method Details

    • read

      public void read(Consumer<ReadResult<T>> consumer)
      Description copied from class: AbstractReadHandler
      Reads the file and invokes the given consumer for each row result.
      Specified by:
      read in class AbstractReadHandler<T>
      Parameters:
      consumer - Callback to receive parsed and validated row results
    • readAsStream

      public Stream<ReadResult<T>> readAsStream()
      Reads the CSV file as a stream of row results.

      Important: The returned stream holds file resources (CSVReader, temp file). Always use try-with-resources to ensure proper cleanup:

      
       try (Stream<ReadResult<T>> stream = handler.readAsStream()) {
           stream.forEach(result -> ...);
       }
       
      Specified by:
      readAsStream in class AbstractReadHandler<T>
      Returns:
      A stream of parsed and validated row results