UnsyncByteArrayOutputStream extends OutputStream { public void writeTo(OutputStream outputStream) throws IOException { outputStream.write(_buffer, 0, _index); } UnsyncByteArrayOutputStream();  UnsyncByteArrayOutputStream(int size); void reset(); int size(); byte[] toByteArray(); @Override String toString(); String toString(String charsetName); byte[] unsafeGetByteArray(); ByteBuffer unsafeGetByteBuffer(); @Override void write(byte[] bytes); @Override void write(byte[] bytes, int offset, int length); @Override void write(int b); void writeTo(OutputStream outputStream);  }
@Test public void testWriteTo() throws IOException { UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream(); unsyncByteArrayOutputStream.write(_BUFFER); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); unsyncByteArrayOutputStream.writeTo(byteArrayOutputStream); Assert.assertTrue( Arrays.equals(_BUFFER, byteArrayOutputStream.toByteArray())); }