Class ExposedByteArrayOutputStream

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

    @Internal
    public class ExposedByteArrayOutputStream
    extends java.io.ByteArrayOutputStream
    ByteArrayOutputStream special cased to treat writes of a single byte-array specially. When calling toByteArray() after writing only one byte[] using writeAndOwn(byte[]), it will return that array directly.
    • Field Summary

      • Fields inherited from class java.io.ByteArrayOutputStream

        buf, count
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void reset()  
      byte[] toByteArray()  
      void write​(byte[] b, int off, int len)  
      void write​(int b)  
      void writeAndOwn​(byte[] b)
      Write b to the stream and take the ownership of b.
      • Methods inherited from class java.io.ByteArrayOutputStream

        close, size, toString, toString, toString, toString, writeBytes, writeTo
      • Methods inherited from class java.io.OutputStream

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

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

      • ExposedByteArrayOutputStream

        public ExposedByteArrayOutputStream()
    • Method Detail

      • writeAndOwn

        public void writeAndOwn​(byte[] b)
                         throws java.io.IOException
        Write b to the stream and take the ownership of b. If the stream is empty, b itself will be used as the content of the stream and no content copy will be involved.

        Note: After passing any byte array to this method, it must not be modified again.

        Throws:
        java.io.IOException
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
        Overrides:
        write in class java.io.ByteArrayOutputStream
      • write

        public void write​(int b)
        Overrides:
        write in class java.io.ByteArrayOutputStream
      • toByteArray

        public byte[] toByteArray()
        Overrides:
        toByteArray in class java.io.ByteArrayOutputStream
      • reset

        public void reset()
        Overrides:
        reset in class java.io.ByteArrayOutputStream