Class SensibleByteArrayOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable
    Direct Known Subclasses:
    PostgresByteArrayOutputStream

    public class SensibleByteArrayOutputStream
    extends java.io.ByteArrayOutputStream
    A subclass of ByteArrayOutputStream that behaves a little more sensibly when handling large writes followed by small writes.
    Author:
    Matthew Wakeling
    • 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 assureSize​(int newSize)
      Resizes the buffer to ensure it is as large as newSize.
      void write​(byte[] b, int off, int len)
      void write​(int b)
      • Methods inherited from class java.io.ByteArrayOutputStream

        close, reset, size, toByteArray, 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

      • SensibleByteArrayOutputStream

        public SensibleByteArrayOutputStream()
        See Also:
        ByteArrayOutputStream
      • SensibleByteArrayOutputStream

        public SensibleByteArrayOutputStream​(int size)
        Parameters:
        size - the initial size of the byte array
        See Also:
        ByteArrayOutputStream
    • Method Detail

      • write

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

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

        public void assureSize​(int newSize)
        Resizes the buffer to ensure it is as large as newSize.
        Parameters:
        newSize - the new minimum size of the buffer