private BufferBlock fetchFromChannel(final long regional, final int length,
FileMode mode, MemoryModel memoryModel) throws IOException {
final boolean readwrite = mode.isContent();
BufferBlock block = null;
ByteBuffer buf;
final int minimum = pickMinimumSize(regional, length);
/*
* Needed to make sure the file is synched. There were some intermittened
* failures with HardRegionIndexer while it was scanning the entire file
* without this force. Therefore it must be here. Some portions of the file
* were lagging with the synch to the physical file.
*/
channel.force(true);
switch (memoryModel) {
case MappedFile:
final MapMode mapMode = ((readwrite) ? MapMode.READ_WRITE
: MapMode.READ_ONLY);
buf = this.channel.map(mapMode, regional, minimum);
buf.clear();
block = new BufferBlock(buf, BitBuffer.wrap(buf), regional, buf.capacity());
block.getByteBuffer().order(this.byteOrder);
System.gc();
break;
case DirectBuffer:
System.out.flush();
buf = ByteBuffer.allocateDirect(minimum);
buf.clear();
this.channel.position(regional);
int s = this.channel.read(buf);
buf.clear();
buf = BufferUtils.asReadonly(buf);
block = new BufferBlock(buf, BitBuffer.wrap(buf), regional, s);
block.getByteBuffer().order(this.byteOrder);
break;
case ByteArray:
buf = ByteBuffer.allocate(minimum);
buf.clear();
this.channel.position(regional);
s = this.channel.read(buf);
buf.clear();
buf = BufferUtils.asReadonly(buf);
block = new BufferBlock(buf, BitBuffer.wrap(buf), regional, s);
block.getByteBuffer().order(this.byteOrder);
break;
default:
throw new IllegalStateException("Unknown memory model encountered "