RandomAccessData { public InputStream asInputStream(final int offset, final int length) { return new ByteArrayInputStream(buffer, 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 testAsInputStream() throws Exception { RandomAccessData stream = new RandomAccessData(); stream.asOutputStream().write(TEST_DATA_A); InputStream in = stream.asInputStream(1, 1); assertEquals(0x02, in.read()); assertEquals(-1, in.read()); in.close(); }