}
}
public ByteBuffer slice(boolean readOnly, long position, int length) {
if( this.readOnly && !readOnly ) {
throw new IOPagingException("read only");
}
int bufferIndex = (int) (position / bufferSize);
int bufferOffset = (int) (position % bufferSize);
ByteBuffer buffer = loadBuffer(bufferIndex);
buffer = position(buffer, bufferOffset);
int remaining = buffer.remaining();
if (length > remaining) {
try {
buffer = channel.map( readOnly ? MapMode.READ_ONLY : MapMode.READ_WRITE, position, length);
bounderyBuffers.add(buffer);
return buffer;
} catch (IOException e) {
throw new IOPagingException(e);
}
}
return ((ByteBuffer) buffer.limit(buffer.position()+length)).slice();
}