Class FastByteArrayOutputStream

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

    public class FastByteArrayOutputStream
    extends java.io.ByteArrayOutputStream
    A speedy implementation of ByteArrayOutputStream. It's not synchronized, and it does not copy buffers when it's expanded. There's also no copying of the internal buffer if it's contents is extracted with the writeTo(stream) method.
    Version:
    $Revision: 1.2 $
    Author:
    Rickard Oberg, Scott Farquhar
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int blockSize  
      private byte[] buffer
      Internal buffer.
      private java.util.LinkedList buffers  
      private static int DEFAULT_BLOCK_SIZE  
      private int index  
      private int size  
      • Fields inherited from class java.io.ByteArrayOutputStream

        buf, count
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void flush()  
      void reset()  
      int size()  
      byte[] toByteArray()  
      java.lang.String toString()  
      java.lang.String toString​(java.lang.String enc)  
      void write​(byte[] data, int offset, int length)  
      void write​(int datum)  
      void writeTo​(java.io.OutputStream out)  
      • Methods inherited from class java.io.ByteArrayOutputStream

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

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

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

      • buffer

        private byte[] buffer
        Internal buffer.
      • buffers

        private java.util.LinkedList buffers
      • index

        private int index
      • size

        private int size
      • blockSize

        private int blockSize
    • Constructor Detail

      • FastByteArrayOutputStream

        public FastByteArrayOutputStream()
      • FastByteArrayOutputStream

        public FastByteArrayOutputStream​(int aSize)
    • Method Detail

      • writeTo

        public void writeTo​(java.io.OutputStream out)
                     throws java.io.IOException
        Overrides:
        writeTo in class java.io.ByteArrayOutputStream
        Throws:
        java.io.IOException
      • size

        public int size()
        Overrides:
        size in class java.io.ByteArrayOutputStream
      • toByteArray

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

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

        public void write​(byte[] data,
                          int offset,
                          int length)
        Overrides:
        write in class java.io.ByteArrayOutputStream
      • reset

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

        public java.lang.String toString​(java.lang.String enc)
                                  throws java.io.UnsupportedEncodingException
        Overrides:
        toString in class java.io.ByteArrayOutputStream
        Throws:
        java.io.UnsupportedEncodingException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.io.ByteArrayOutputStream
      • flush

        public void flush()
                   throws java.io.IOException
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.ByteArrayOutputStream
        Throws:
        java.io.IOException