* into memory if we only need to look at one 4K block in it. Since the
* cache is checked first, if the block does already exist in the memory
* mapped case, then the cached block will be used. Also note that the fetch
* version with MemoryModel, does not cache the returned buffers.
*/
final PartialBuffer buf = loader.fetchMinimum(regional,
AbstractRawIterator.SEARCH_LENGTH, MemoryModel.ByteArray);
final int p = (int) (global - segment.mapRegionalToGlobal(buf
.getStartRegional()));
int maxSearch = (int) buf.getLength() - p;
maxSearch = (maxSearch < AbstractRawIterator.SEARCH_LENGTH) ? maxSearch
: AbstractRawIterator.SEARCH_LENGTH;
/*
* If we don't have enough bytes in this segment for even the minLength,
* then no more records can be found here. The next segment, must contain a
* record at its begining, therefore we can simply align there and call
* hasNext() to confirm and apply the recordFilter if one has been defined.
* If hasNext() can't fullfill the request due to a recordFilter, it will
* return false.
*/
if (maxSearch < this.pattern.minLength()) {
final long nextSegmentStart = segment.getEndGlobal();
setPosition(nextSegmentStart);
return (this.hasNext() ? OK : NOT_OK);
}
buf.getByteBuffer().limit(p + maxSearch);
final long local = this.searchForRecordStart(buf.getByteBuffer(), p, maxSearch);
if (local == -1) {
/*
* Current segment did not contain a beginning of a packet, therefore move
* on to the next segment. The start of each segment should begin with a
* record, so this we should find the next record at startNextSegment
* position, although if the file is corrupt, then we might need to search
* through it until the next record.
*/
final long startNextSegment = segment.getEnd();
if (startNextSegment == this.edits.getLength()) {
/*
* No more segments, so we just searched through last segment and did
* not find start of record. Therefore seek to the end past the last
* record.
*/
this.seekEnd();
return NOT_OK;
} else {
/*
* Every segment always starts with atleast 1 record. It is illegal to
* have segments with not records in them in any of the file formats.
*/
this.setPosition(startNextSegment);
return (this.hasNext() ? OK : NOT_OK);
}
}
final long reg = buf.mapLocalToRegional(local);
@SuppressWarnings("unused")
final long glob = segment.mapRegionalToGlobal(reg);
// if (TestFilter.positions.contains(glob) == false) {
// System.out.printf("Not found in positions %d\n", glob);