@Test public void getStream() throws IOException { when(posReader.get(0)).thenReturn(10L); when(lenReader.get(0)).thenReturn(3); when(dataReader.get(10)).thenReturn((byte) 1); when(dataReader.get(11)).thenReturn((byte) 2); when(dataReader.get(12)).thenReturn((byte) -1); byte[] bytes = new byte[3]; assertEquals(3, new BaseByteArrayReader(dataReader, posReader, lenReader).getStream(0).read(bytes)); assertArrayEquals(new byte[]{1, 2, -1}, bytes); }
@Override public InputStream getStream(long pos) { final long start = posReader.get(pos); final int size = lenReader.get(pos); return new InputStream() { long cursor = start; @Override public int read() { if (available() > 0) { final int b = dataReader.get(cursor) & 0xFF; cursor++; return b; } return -1; } @Override public int available() { return (int) (start + size - cursor); } }; }
BaseByteArrayReader implements ByteArrayReader { @Override public InputStream getStream(long pos) { final long start = posReader.get(pos); final int size = lenReader.get(pos); return new InputStream() { long cursor = start; @Override public int read() { if (available() > 0) { final int b = dataReader.get(cursor) & 0xFF; cursor++; return b; } return -1; } @Override public int available() { return (int) (start + size - cursor); } }; } }
BaseByteArrayReader implements ByteArrayReader { @Override public InputStream getStream(long pos) { final long start = posReader.get(pos); final int size = lenReader.get(pos); return new InputStream() { long cursor = start; @Override public int read() { if (available() > 0) { final int b = dataReader.get(cursor) & 0xFF; cursor++; return b; } return -1; } @Override public int available() { return (int) (start + size - cursor); } }; } BaseByteArrayReader(ByteReader dataReader, LongReader posReader, IntReader lenReader); }
BaseByteArrayReader implements ByteArrayReader { @Override public InputStream getStream(long pos) { final long start = posReader.get(pos); final int size = lenReader.get(pos); return new InputStream() { long cursor = start; @Override public int read() { if (available() > 0) { final int b = dataReader.get(cursor) & 0xFF; cursor++; return b; } return -1; } @Override public int available() { return (int) (start + size - cursor); } }; } BaseByteArrayReader(ByteReader dataReader, LongReader posReader, IntReader lenReader); @Override boolean isReadable(); @Override byte[] get(long pos); @Override InputStream getStream(long pos); @Override void release(); }
BaseByteArrayReader implements ByteArrayReader { @Override public InputStream getStream(long pos) { final long start = posReader.get(pos); final int size = lenReader.get(pos); return new InputStream() { long cursor = start; @Override public int read() { if (available() > 0) { final int b = dataReader.get(cursor) & 0xFF; cursor++; return b; } return -1; } @Override public int available() { return (int) (start + size - cursor); } }; } BaseByteArrayReader(ByteReader dataReader, LongReader posReader, IntReader lenReader); @Override boolean isReadable(); @Override byte[] get(long pos); @Override InputStream getStream(long pos); @Override void release();  }