RandomAccessData { public void readFrom(InputStream inStream, int offset, int length) throws IOException { ensureCapacity(offset + length); ByteStreams.readFully(inStream, buffer, offset, length); size = offset + length; } RandomAccessData();  RandomAccessData(byte[] initialBuffer);  RandomAccessData(int initialBufferSize); RandomAccessData increment(); byte[] array(); int size(); void resetTo(int position); OutputStream asOutputStream(); InputStream asInputStream(final int offset, final int length); void writeTo(OutputStream out, int offset, int length); void readFrom(InputStream inStream, int offset, int length); RandomAccessData copy(); @Override boolean equals(@Nullable Object other); @Override int hashCode(); @Override String toString(); static final UnsignedLexicographicalComparator UNSIGNED_LEXICOGRAPHICAL_COMPARATOR; }
@Test public void testReadFrom() throws Exception { ByteArrayInputStream bais = new ByteArrayInputStream(TEST_DATA_A); RandomAccessData stream = new RandomAccessData(); stream.readFrom(bais, 3, 2); assertArrayEquals( new byte[] {0x00, 0x00, 0x00, 0x01, 0x02}, Arrays.copyOf(stream.array(), stream.size())); bais.close(); }