I have a situation where in I keep reading with a ByteBuffer as below.
ByteBuffer buffer = MappedByteBuffer.allocateDirect(Constants.BUFFER_SIZE);
But when the reading reaches the boundary (when the remaining bytes to read is less than BUFFER_SIZE) I need to read only the boundaryLimit - FileChannel's current position .
Means the boundary limit is x and current positions is y, then I need to read bytes from y till x and not beyond that.
How do I achieve this ?
I dont want to create another instance with new capacity.
Its misleading to use MappedByteBuffer here. You should use
If you read less than a full amount of bytes its not a problem
EDIT: To read from a random location in a file.