- java.lang.Object
-
- com.pervasive.datarush.operators.io.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 Summary
Constructors Constructor Description AbstractRecordFormatter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
bindInput(SteppableRecordValued source)
Simple implementation which passes an input port buffer tobindInputFields(RecordValued)
.protected abstract void
bindInputFields(RecordValued source)
Provides the buffer holding input data to be formatted.abstract void
close()
Called to signal that writing is complete.protected abstract void
formatRecord()
Called to write a formatted record.protected abstract void
initialize(ByteSink sink, WriteMode mode)
Prepares the formatter for writing to the provided sink.void
writeData(ByteSink sink, WriteMode mode)
Simple implementation of a control loop formatting records.
-
-
-
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
-
bindInput
public final void bindInput(SteppableRecordValued source)
Simple implementation which passes an input port buffer tobindInputFields(RecordValued)
.- Specified by:
bindInput
in interfaceDataFormat.DataFormatter
- Parameters:
source
- the input port providing records
-
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 beforeformatRecord()
is called.This method is always called, even if the input has no data.
- Parameters:
sink
- the target to which data is writtenmode
- 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 throughbindInputFields(RecordValued)
and write it to the sink passed toinitialize(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 withinitialize(ByteSink, WriteMode)
. If successfully initialized, it then iterates over the previously bound input, callingformatRecord()
for each record on the port.- Specified by:
writeData
in interfaceDataFormat.DataFormatter
- Parameters:
sink
- the data sink to which formatted records are to be writtenmode
- the access mode for the write
-
close
public abstract void close()
Called to signal that writing is complete. IfbindInputFields(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 interfaceDataFormat.DataFormatter
-
-