ByteArray { public void writeTo(OutputStream out) throws IOException { out.write(bytes, offset, length); } ByteArray(byte[] bytes);  ByteArray(byte[] bytes, int offset, int length); byte[] getRawBytes(); int getOffset(); int getLength(); byte[] toByteArray(); InputStream toInputStream(); void writeTo(OutputStream out); @Override String toString();  }
@Test public void writeTo() throws Exception { ByteArray ba; ba = new ByteArray(data); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ba.writeTo(baos); assertArrayEquals(data, baos.toByteArray()); }