FileChannelRandomAccessSource implements RandomAccessSource { public int get(long position) throws IOException { return source.get(position); } FileChannelRandomAccessSource(FileChannel channel); void close(); int get(long position); int get(long position, byte[] bytes, int off, int len); long length();  }
@Test public void testGet() throws Exception { FileChannelRandomAccessSource s = new FileChannelRandomAccessSource(channel); try{ for(int i = 0; i < data.length; i++){ int ch = s.get(i); Assert.assertFalse("EOF hit unexpectedly at " + i + " out of " + data.length, ch == -1); Assert.assertEquals("Position " + i, data[i], (byte)ch); } Assert.assertEquals(-1, s.get(data.length)); } finally { s.close(); } }