Class ValidatingReader


public class ValidatingReader extends FilteringReader
A proxy that validates records by applying a set of filters.
  • Constructor Details

    • ValidatingReader

      public ValidatingReader(DataReader reader, DataWriter discardWriter, String discardReasonFieldName)
      Accepts the DataReader to validate and the DataWriter to send discarded records to. The exceptionOnFailure flag will be turned off if discardWriter contains a non-null value. Attempting to turn exceptionOnFailure on while a discardWriter is present will result in an exception.
      Parameters:
      reader - the source reader to filter.
      discardWriter - the discard sink for disallowed records.
      discardReasonFieldName - the field in the record to place the description of the filter that disallowed it or null if one should not be added.
    • ValidatingReader

      public ValidatingReader(DataReader reader, DataWriter discardWriter)
      Accepts the DataReader to validate and the DataWriter to send discarded records to. The exceptionOnFailure flag will be turned off if discardWriter contains a non-null value. Attempting to turn exceptionOnFailure on while a discardWriter is present will result in an exception.
      Parameters:
      reader - the source reader to filter.
      discardWriter - the discard sink for disallowed records.
    • ValidatingReader

      public ValidatingReader(DataReader reader)
      Creates a reader that throws an exception for the first record failing validation.
  • Method Details

    • isExceptionOnFailure

      public boolean isExceptionOnFailure()
      Indicates if a record failing validation throws an exception instead of being discarded with a warning (defaults to true unless a discard writer is set).
    • setExceptionOnFailure

      public ValidatingReader setExceptionOnFailure(boolean exceptionOnFailure)
      Indicates if a record failing validation throws an exception instead of being discarded with a warning; cannot be turned on while a discard writer is set.
    • isRecordStackTraceInMessage

      public boolean isRecordStackTraceInMessage()
      Indicates if the warning recorded for each discarded record captures a stack trace (defaults to true).
    • setRecordStackTraceInMessage

      public ValidatingReader setRecordStackTraceInMessage(boolean recordStackTraceInMessage)
      Indicates if the warning recorded for each discarded record captures a stack trace (defaults to true).
    • discard

      protected Record discard(Record record, Filter filter)
      Description copied from class: FilteringReader
      Handles a record rejected by filter; writes it to the discard writer (adding the discard reason field if configured) and returns null so it is dropped.
      Overrides:
      discard in class FilteringReader
    • 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 FilteringReader