Code example for MappedByteBuffer

Methods: duplicate, position, remaining

     * @return buffer with portion of file content 
     * @throws IOException on any fail of I/O operation 
    public synchronized ByteBuffer readBytes(int length) throws IOException
        int remaining = buffer.remaining() - position;
        if (length > remaining)
            throw new IOException(String.format("mmap segment underflow; remaining is %d but %d requested",
                                                remaining, length));
        ByteBuffer bytes = buffer.duplicate();
        bytes.position(buffer.position() + position).limit(buffer.position() + position + length);
        position += length;
        return bytes;
    public final void readFully(byte[] buffer) throws IOException
        throw new UnsupportedOperationException("use readBytes instead");