Class UnsafeByteArrayOutputStream

This class is used as a wrapper to a byte array, extending
OutputStream. Data is written in the given byte[] buffer, until its
length is insufficient. Than the buffer size is doubled and the data is
written.
This class is Unsafe as it is using a buffer which potentially can be changed
from the outside. Moreover, when toByteArray() is called, the buffer
itself is returned, and not a copy.

WARNING: This API is experimental and might change in incompatible ways in the next release.

toByteArray

public byte[] toByteArray()

Returns the byte array saved within the buffer AS IS.

Returns:

the actual inner buffer - not a copy of it.

length

public int length()

Returns the number of relevant bytes. This objects makes sure the buffer
is at least the size of it's data. But it can also be twice as big. The
user would want to process the relevant bytes only. For that he would
need the count.