ArrayRandomAccessSource implements RandomAccessSource { public int get(long offset) { if (offset >= array.length) return -1; return 0xff & array[(int)offset]; } ArrayRandomAccessSource(byte[] array); int get(long offset); int get(long offset, byte[] bytes, int off, int len); long length(); void close();  }
@Test public void testGet() throws Exception { ArrayRandomAccessSource s = new ArrayRandomAccessSource(data); try{ for(int i = 0; i < data.length; i++){ int ch = s.get(i); Assert.assertFalse(ch == -1); Assert.assertEquals("Position " + i, data[i], (byte)ch); } Assert.assertEquals(-1, s.get(data.length)); } finally { s.close(); } }