UnsyncByteArrayOutputStream extends OutputStream { public byte[] unsafeGetByteArray() { return _buffer; } 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 testUnsafeGetByteArray() throws Exception { UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream(); unsyncByteArrayOutputStream.write(_BUFFER); byte[] bytes1 = unsyncByteArrayOutputStream.unsafeGetByteArray(); Assert.assertTrue(Arrays.equals(_BUFFER, bytes1)); Assert.assertSame( _bufferField.get(unsyncByteArrayOutputStream), bytes1); byte[] bytes2 = unsyncByteArrayOutputStream.unsafeGetByteArray(); Assert.assertTrue(Arrays.equals(_BUFFER, bytes2)); Assert.assertSame(bytes1, bytes2); ByteBuffer byteBuffer = unsyncByteArrayOutputStream.unsafeGetByteBuffer(); Assert.assertSame(bytes1, byteBuffer.array()); }