Class ReadByLine

Object
ReadByLine
All Implemented Interfaces:
AutoCloseable

public class ReadByLine extends Object implements AutoCloseable
An opened-CSV file that is read line-by-line and processed.
Author:
Owen Feehan
  • Constructor Details

    • ReadByLine

      public ReadByLine(Path filePath, CSVReader csvReader)
      Creates a new ReadByLine instance.
      Parameters:
      filePath - Path to the CSV file that will be read.
      csvReader - How the CSV will be read.
  • Method Details

    • headers

      public String[] headers() throws CSVReaderException
      The headers of the CSV file.
      Returns:
      a string or null if the headers don't exist.
      Throws:
      CSVReaderException - if the file cannot be opened successfully.
    • read

      public int read(ProcessCSVLine lineProcessor) throws CSVReaderException
      Reads a CSV-file iterating through each row and passing it to lineProcessor

      This will automatically close any opened-files

      Parameters:
      lineProcessor - called one for each row incrementally
      Returns:
      the number of lines read
      Throws:
      CSVReaderException - if any file-system I/O errors occur.
    • close

      public void close() throws CSVReaderException
      Closes any opened-files
      Specified by:
      close in interface AutoCloseable
      Throws:
      CSVReaderException - if any file-system I/O errors occur.