UnsyncByteArrayOutputStream extends OutputStream { @Override public void write(byte[] bytes) { write(bytes, 0, bytes.length); } 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 testWrite() { UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream(); for (int i = 0; i < _BUFFER_SIZE; i++) { unsyncByteArrayOutputStream.write(i); Assert.assertEquals(i + 1, unsyncByteArrayOutputStream.size()); } Assert.assertTrue( Arrays.equals(_BUFFER, unsyncByteArrayOutputStream.toByteArray())); }