Class ProxyReader

Direct Known Subclasses:
AggregateReader, AsyncReader, AsyncTaskReader, BufferedReader, DebugReader, FilteringReader, GroupByReader, IntegrationProxyReader, LimitReader, MeteredReader, RemoveDuplicatesReader, RetryingReader, SortingReader, TailProxyReader, TeeReader, TimedReader, TransformingReader

public class ProxyReader extends DataReader
Abstract super-class for obtaining records from another DataReader, possibly transforming them along the way. The only method that a subclass should implement is interceptRecord(Record).
  • Constructor Details

    • ProxyReader

      public ProxyReader(DataReader nestedDataReader)
      Creates a proxy for the given (non-null) reader, which is opened and closed along with this proxy.
  • Method Details

    • map

      public static ProxyReader map(DataReader reader, Function<Record,Record> mapper) throws Throwable
      Wraps the reader in a proxy that passes each record through the mapper; a null result drops the record.
      Throws:
      Throwable
    • map

      public static ProxyReader map(DataReader reader, BiFunction<ProxyReader,Record,Record> mapper) throws Throwable
      Wraps the reader in a proxy that passes itself and each record to the mapper; a null result drops the record.
      Throws:
      Throwable
    • getNestedReader

      public DataReader getNestedReader()
      Description copied from class: DataReader
      Returns the DataReader held inside this one or null if there isn't one.
      Overrides:
      getNestedReader in class DataReader
    • setNestedDataReader

      protected void setNestedDataReader(DataReader nestedDataReader)
      Make sure to close old target and open the new one or call with true.
    • setNestedDataReader

      protected void setNestedDataReader(DataReader nestedDataReader, boolean manageLifecycle) throws DataException
      Replaces the nested reader; with manageLifecycle the old reader is closed and, if this proxy is open, the new one is opened.
      Throws:
      DataException
    • available

      public int available() throws DataException
      Description copied from class: DataReader
      Returns the number of records that can probably be read without blocking.
      Overrides:
      available in class DataReader
      Throws:
      DataException
    • 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
    • close

      public void close() throws DataException
      Description copied from class: DataEndpoint
      Indicates that this endpoint has finished reading or writing.
      Overrides:
      close in class DataEndpoint
      Throws:
      DataException
    • interceptRecord

      protected Record interceptRecord(Record record) throws Throwable
      Overridden by subclasses to transform, drop, or observe a record on its way through this proxy.

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

      • Return the record (possibly modified) to pass it downstream.
      • Return null to drop the record; the framework reads the next one.
      • Throw to fail the pipeline; the framework wraps the throwable in a DataException with .setRecord(record).
      • The nested DataReader is opened and closed for you; do not read from it here.
      • Do not call DataEndpoint.incrementRecordCount() here.
      Throws:
      Throwable
    • 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
    • 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