Class BufferOutputStream

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

    public final class BufferOutputStream
    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. It also does not re-grow it's internal buffer.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) byte[] buffer  
      (package private) int limit  
      (package private) int offset  
      (package private) int pos  
    • 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.
      Buffer getNextBuffer​(int len)  
      void reset()  
      int size()  
      Buffer toBuffer()  
      byte[] toByteArray()  
      void write​(byte[] b, int off, int len)  
      void write​(int 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
      • offset

        int offset
      • limit

        int limit
      • pos

        int pos
    • Constructor Detail

      • BufferOutputStream

        public BufferOutputStream​(int size)
      • BufferOutputStream

        public BufferOutputStream​(byte[] buffer)
      • BufferOutputStream

        public BufferOutputStream​(Buffer data)
    • Method Detail

      • write

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

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

        public Buffer getNextBuffer​(int len)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • checkCapacity

        private void checkCapacity​(int minimumCapacity)
                            throws java.io.IOException
        Ensures the the buffer has at least the minimumCapacity specified.
        Parameters:
        i -
        Throws:
        java.io.EOFException
        java.io.IOException
      • reset

        public void reset()
      • toBuffer

        public Buffer toBuffer()
      • toByteArray

        public byte[] toByteArray()
      • size

        public int size()