Class DirectByteArrayOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public class DirectByteArrayOutputStream
    extends java.io.OutputStream
    Byte array output stream that exposes the byte array directly
    • Constructor Summary

      Constructors 
      Constructor Description
      DirectByteArrayOutputStream​(int size)
      Construct a new DirectByteArrayOutputStream with the given initial size.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] getArray()
      Get a copy of the bytes written to this stream.
      byte[] getArrayDirect()
      Get the underlying byte array directly without copying.
      int size()
      Get the current number of bytes written to this stream.
      void write​(int b)  
      • Methods inherited from class java.io.OutputStream

        close, flush, nullOutputStream, write, write
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DirectByteArrayOutputStream

        public DirectByteArrayOutputStream​(int size)
        Construct a new DirectByteArrayOutputStream with the given initial size.
        Parameters:
        size - Initial size of the internal buffer
    • Method Detail

      • write

        public void write​(int b)
                   throws java.io.IOException
        Specified by:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • size

        public int size()
        Get the current number of bytes written to this stream.
        Returns:
        Number of bytes written
      • getArrayDirect

        public byte[] getArrayDirect()
        Get the underlying byte array directly without copying.
        Returns:
        Direct byte array reference
      • getArray

        public byte[] getArray()
        Get a copy of the bytes written to this stream.
        Returns:
        Copy of the byte array