spring-framework / org.springframework.util / FastByteArrayOutputStream / toByteArrayUnsafe

toByteArrayUnsafe

open fun toByteArrayUnsafe(): ByteArray

Convert the stream's data to a byte array and return the byte array.

Also replaces the internal structures with the byte array to conserve memory: if the byte array is being made anyways, mind as well as use it. This approach also means that if this method is called twice without any writes in between, the second call is a no-op.

This method is "unsafe" as it returns the internal buffer. Callers should not modify the returned buffer.

Return
the current contents of this output stream, as a byte array.

See Also
#size()#toByteArray()