GetBufferedRandomAccessSource implements RandomAccessSource { public int get(long position) throws IOException { if (position < getBufferStart || position > getBufferEnd){ int count = source.get(position, getBuffer, 0, getBuffer.length); if (count == -1) return -1; getBufferStart = position; getBufferEnd = position + count - 1; } int bufPos = (int)(position-getBufferStart); return 0xff & getBuffer[bufPos]; } GetBufferedRandomAccessSource(RandomAccessSource source); int get(long position); int get(long position, byte[] bytes, int off, int len); long length(); void close();  }
@Test public void testSmallSizedFile() throws Exception { byte[] data = new byte[]{42}; ArrayRandomAccessSource arrayRAS = new ArrayRandomAccessSource(data); GetBufferedRandomAccessSource bufferedRAS = new GetBufferedRandomAccessSource(arrayRAS); Assert.assertEquals(42, bufferedRAS.get(0)); }