Class JPPFByteArrayOutputStream

java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
org.jppf.utils.streams.JPPFByteArrayOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class JPPFByteArrayOutputStream extends ByteArrayOutputStream
Extension of ByteArrayOutputStream, providing a faster toByteArray() method that does not involve copying its internal buffer.
Author:
Laurent Cohen
  • Constructor Details

    • JPPFByteArrayOutputStream

      public JPPFByteArrayOutputStream()
      Instantiate this stream with a default size.
    • JPPFByteArrayOutputStream

      public JPPFByteArrayOutputStream(int size)
      Instantiate this stream with the specified size.
      Parameters:
      size - the initial size of the underlying buffer.
  • Method Details

    • toByteArray

      public byte[] toByteArray()
      Override of toByteArray() that returns a reference to the internal buffer instead of copy of it, significantly increasing the performance of this operation.
      Overrides:
      toByteArray in class ByteArrayOutputStream
      Returns:
      the content of the stream as an array of bytes.
      See Also:
    • getBuf

      public byte[] getBuf()
      Provide access to the internal buffer.
      Returns:
      an array of bytes.