Class ByteArrayOutputStream

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

    public class ByteArrayOutputStream
    extends java.io.OutputStream
    Very similar to the java.io.ByteArrayOutputStream but this version is not thread safe and the resulting data is returned in a Buffer to avoid an extra byte[] allocation.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) byte[] buffer  
      (package private) int size  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void checkCapacity​(int minimumCapacity)
      Ensures the the buffer has at least the minimumCapacity specified.
      void reset()  
      int size()  
      Buffer toBuffer()  
      byte[] toByteArray()  
      void write​(byte[] b, int off, int len)  
      void write​(int b)  
      void write​(Buffer b)  
      • Methods inherited from class java.io.OutputStream

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

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

      • buffer

        byte[] buffer
      • size

        int size
    • Constructor Detail

      • ByteArrayOutputStream

        public ByteArrayOutputStream()
      • ByteArrayOutputStream

        public ByteArrayOutputStream​(int capacity)
    • Method Detail

      • write

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

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

        public void write​(Buffer b)
      • checkCapacity

        private void checkCapacity​(int minimumCapacity)
        Ensures the the buffer has at least the minimumCapacity specified.
        Parameters:
        minimumCapacity -
      • reset

        public void reset()
      • toBuffer

        public Buffer toBuffer()
      • toByteArray

        public byte[] toByteArray()
      • size

        public int size()