Class AbstractReader

Direct Known Subclasses:
ExcelReader, GoogleSheetReader, ParsingReader, TextReader

public abstract class AbstractReader extends DataReader
Abstract super-class, with some common logic, for reading records. The only method subclasses must implement is fillRecord(Record).
  • Field Details

    • fieldNames

      protected String[] fieldNames
    • currentRecord

      protected Record currentRecord
    • startingRow

      protected int startingRow
    • lastRow

      protected int lastRow
  • Constructor Details

    • AbstractReader

      public AbstractReader()
  • Method Details

    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Endpoint
      Adds this endpoint's current state to a DataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.
      Overrides:
      addExceptionProperties in class DataReader
    • isFieldNamesInFirstRow

      public boolean isFieldNamesInFirstRow()
      Indicates if the first row holds the field names instead of data (default is false).
    • setFieldNamesInFirstRow

      public AbstractReader setFieldNamesInFirstRow(boolean fieldNamesInFirstRow)
      Indicates if the first row holds the field names instead of data (default is false); must be called before open().
    • getFieldNames

      public String[] getFieldNames()
      Returns a copy of the field names that were set or read from the first row, or an empty array if there are none yet.
    • setFieldNames

      public AbstractReader setFieldNames(String... fieldNames)
      Sets the names given to each record's fields, taking precedence over names in the first row; must be called before open().
    • setFieldNames

      public AbstractReader setFieldNames(Collection<String> fieldNames)
      Sets the names given to each record's fields, taking precedence over names in the first row; must be called before open().
    • setStartingRow

      public AbstractReader setStartingRow(int startingRow)
      Sets the 0-based index of the first row to read; earlier rows are skipped when the reader is opened (default is 0).
    • getStartingRow

      public int getStartingRow()
      Returns the 0-based index of the first row to read; earlier rows are skipped when the reader is opened (default is 0).
    • setLastRow

      public AbstractReader setLastRow(int lastRow)
      Sets the 0-based index of the last row to read or -1 to read to the end (default is -1).
    • getLastRow

      public int getLastRow()
      Returns the 0-based index of the last row to read or -1 to read to the end (default is -1).
    • setSkipEmptyRows

      public AbstractReader setSkipEmptyRows(boolean skipEmptyRows)
      Indicates that rows with only null values should not be returned by the reader (default is false).
    • isSkipEmptyRows

      public boolean isSkipEmptyRows()
      Indicates that rows with only null values should not be returned by the reader (default is false).
    • open

      public void open() throws DataException
      Description copied from class: DataEndpoint
      Makes this endpoint ready for reading or writing.
      Overrides:
      open in class DataEndpoint
      Throws:
      DataException
    • read

      public Record read() throws DataException
      Description copied from class: DataReader
      Reads the next record from this DataReader and increases the record-count by 1. This method will first read any pushed (DataReader.push(Record)) records before reading from the underlying source.

      If no record is available, null will be returned. This method blocks until a record is available, the end of the stream is reached, or an exception is thrown.

      Any exception raised while reading will be converted to a DataException using DataObject.exception(Throwable).

      Subclasses generally do not need to override this method, instead they should implement DataReader.readImpl().

      Overrides:
      read in class DataReader
      Throws:
      DataException
      See Also:
    • readImpl

      protected Record readImpl() throws Throwable
      Description copied from class: DataReader
      Overridden by subclasses to read the next record from this DataReader. The default implementation of DataReader.read() now insures that this method will not be called again after it returns a null.

      If no record is available, null will be returned.

      Contract for subclasses (see also docs/authoring/DataReader.md):

      Specified by:
      readImpl in class DataReader
      Throws:
      Throwable
    • fillRecord

      protected abstract boolean fillRecord(Record record) throws Throwable
      Populates the given record with the next row's values; returns false at the end of the input.
      Throws:
      Throwable