RandomAccessData { public void writeTo(OutputStream out, int offset, int length) throws IOException { out.write(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 testWriteTo() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); RandomAccessData stream = new RandomAccessData(); stream.asOutputStream().write(TEST_DATA_B); stream.writeTo(baos, 1, 2); assertArrayEquals(new byte[] {0x05, 0x04}, baos.toByteArray()); baos.close(); }