Class AbstractRecordFormatter

  • All Implemented Interfaces:
    DataFormat.DataFormatter

    public abstract class AbstractRecordFormatter
    extends Object
    implements DataFormat.DataFormatter
    Skeleton implementation of a formatter for writing records to a sink. Provides a basic loop over the input data, deferring to subclasses to do format-specific processing.
    • Constructor Detail

      • AbstractRecordFormatter

        public AbstractRecordFormatter()
    • Method Detail

      • bindInputFields

        protected abstract void bindInputFields​(RecordValued source)
        Provides the buffer holding input data to be formatted. This will be called once, when the input is bound to the formatter.
        Parameters:
        source - a record valued container which will hold the current value to be formatted
      • initialize

        protected abstract void initialize​(ByteSink sink,
                                           WriteMode mode)
                                    throws IOException
        Prepares the formatter for writing to the provided sink. This will be called once, after #bindInput(RecordInput) has been called, but before formatRecord() is called.

        This method is always called, even if the input has no data.

        Parameters:
        sink - the target to which data is written
        mode - how an existing sink should be handled
        Throws:
        IOException - if an I/O error occurs
      • formatRecord

        protected abstract void formatRecord()
                                      throws IOException
        Called to write a formatted record. The method is expected to format the record in the buffer passed in previously through bindInputFields(RecordValued) and write it to the sink passed to initialize(ByteSink, WriteMode).

        This method is called repeatedly while the record source still has data.

        Throws:
        IOException - if an I/O error occurs while writing the record
      • writeData

        public final void writeData​(ByteSink sink,
                                    WriteMode mode)
        Simple implementation of a control loop formatting records. It first initializes the formatter with initialize(ByteSink, WriteMode). If successfully initialized, it then iterates over the previously bound input, calling formatRecord() for each record on the port.
        Specified by:
        writeData in interface DataFormat.DataFormatter
        Parameters:
        sink - the data sink to which formatted records are to be written
        mode - the access mode for the write
      • close

        public abstract void close()
        Called to signal that writing is complete. If bindInputFields(RecordValued) has returned successfully, it is guaranteed that this method will be called, even if errors occur.

        This method is called once, after the last call to formatRecord() Any allocated resources which need to be released should be handled within the implementation of this method.

        Specified by:
        close in interface DataFormat.DataFormatter