A
Source.Reader that implements code common to readers of
FileBasedSources.
Seekability
This reader uses a
ReadableByteChannel created for the file represented by the
corresponding source to efficiently move to the correct starting position defined in the
source. Subclasses of this reader should implement
#startReading to get access to this
channel. If the source corresponding to the reader is for a subrange of a file the
ReadableByteChannel provided is guaranteed to be an instance of the type
SeekableByteChannel, which may be used by subclass to traverse back in the channel to
determine the correct starting position.
Reading Records
Sequential reading is implemented using
#readNextRecord.
Then
FileBasedReader implements "reading a range [A, B)" in the following way.
-
#start opens the file
-
#start seeks the
SeekableByteChannel to A (reading offset ranges for
non-seekable files is not supported) and calls
startReading()
-
#start calls
#advance once, which, via
#readNextRecord, locates
the first record which is at a split point AND its offset is at or after A. If this
record is at or after B,
#advance returns false and reading is finished.
- if the previous advance call returned
true sequential reading starts and
advance() will be called repeatedly
advance() calls
readNextRecord() on the subclass, and stops (returns false) if
the new record is at a split point AND the offset of the new record is at or after B.
Thread Safety
Since this class implements
Source.Reader it guarantees thread safety. Abstract
methods defined here will not be accessed by more than one thread concurrently.