@Override
    public int read() throws IOException
    {
        checkClosed();
        if (pointer >= this.size)
        {
            return -1;
        }
        if (currentBufferPointer >= chunkSize)
        {
            if (bufferListIndex >= bufferListMaxIndex)
            {
                return -1;
            }
            else
            {
                currentBuffer = bufferList.get(++bufferListIndex);
                currentBufferPointer = 0;
            }
        }
        pointer++;
        return currentBuffer.get(currentBufferPointer++) & 0xff;
    }
@Test
    void testPDFBOX5764() throws IOException
    {
        int bufferSize = 4096;
        int limit = 2048;
        ByteBuffer buffer = ByteBuffer.wrap(new byte[bufferSize]);
        buffer.limit(limit);
        try (RandomAccessRead rar = new RandomAccessReadBuffer(buffer))
        {
            byte[] buf = new byte[bufferSize];
            int bytesRead = rar.read(buf);
            assertEquals(limit, bytesRead);
        }
    }