public class

DirectByteArrayOutputStream

extends ByteArrayOutputStream
java.lang.Object
   ↳ java.io.OutputStream
     ↳ java.io.ByteArrayOutputStream
       ↳ com.pnfsoftware.jeb.util.io.DirectByteArrayOutputStream

Class Overview

Extend ByteArrayOutputStream to provide direct access to the underlying byte array. In particular, this class is meant to circumvent the memory consumption issues of toByteArray().

Summary

[Expand]
Inherited Fields
From class java.io.ByteArrayOutputStream
Public Constructors
DirectByteArrayOutputStream()
Public Methods
synchronized ByteBuffer getBytes()
Direct access to the underlying byte array.
byte[] getRawBytes()
Direct access to the underlying byte array.
[Expand]
Inherited Methods
From class java.io.ByteArrayOutputStream
From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable
From interface java.lang.AutoCloseable

Public Constructors

public DirectByteArrayOutputStream ()

Public Methods

public synchronized ByteBuffer getBytes ()

Direct access to the underlying byte array.

Returns
  • a buffer view of the bytes written to the stream

public byte[] getRawBytes ()

Direct access to the underlying byte array. This method is dangerous, but can be used instead of the expensive toByteArray(). It should be used in combination with size(). A safer, as efficient alternative, is getBytes().

Returns
  • array with potentially more bytes than what was actually written to the stream (see size())