int endBlockOffset;
if (indexPosition == blockIndex.getNumEntries() - 1)
// the last block in the block index
endBlockOffset = -1;
else {
ByteRange indexPos = getBlockEntry(indexPosition + 1, blockIndex);
ByteBuffer indexPosBuf = indexPos.getBuf();
endBlockOffset = getBlockIndexOffset(indexPosBuf, indexPos.getStartOffset());
// is this the last block of the current block file?
// then the endBlockOffset should be set to the end of the file
if (getBlockIndexFileId(indexPosBuf, indexPos.getStartOffset()) > fileId)
endBlockOffset = -1;
// endBlockOffset = getBlockOffset(indexPosition + 1, blockIndex);
}
// create a view buffer on the target block
BlockReader targetBlock = null;
try {
targetBlock = mmaped ? getBlock(startBlockOffset, endBlockOffset, dbFiles[fileId]) : getBlock(
startBlockOffset, endBlockOffset, dbFileChannels[fileId]);
} catch (IOException e) {
Logging.logError(Logging.LEVEL_ERROR, this, e);
}
// search for the key in the target block and return the result
ByteRange val = targetBlock.lookup(key);
byte[] result = val == null ? null : val.toBuffer();
targetBlock.free();
return result;
}