Class MemoryLimitsAwareOutputStream

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

    class MemoryLimitsAwareOutputStream
    extends java.io.ByteArrayOutputStream
    This class implements an output stream which can be used for memory limits aware decompression of pdf streams.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int DEFAULT_MAX_STREAM_SIZE
      The maximum size of array to allocate.
      private int maxStreamSize
      The maximum size of array to allocate.
      • Fields inherited from class java.io.ByteArrayOutputStream

        buf, count
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getMaxStreamSize()
      Gets the maximum size which can be occupied by this output stream.
      MemoryLimitsAwareOutputStream setMaxStreamSize​(int maxStreamSize)
      Sets the maximum size which can be occupied by this output stream.
      void write​(byte[] b, int off, int len)
      • Methods inherited from class java.io.ByteArrayOutputStream

        close, reset, size, toByteArray, toString, toString, toString, toString, write, 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
    • Field Detail

      • DEFAULT_MAX_STREAM_SIZE

        private static final int DEFAULT_MAX_STREAM_SIZE
        The maximum size of array to allocate. Attempts to allocate larger arrays will result in an exception.
        See Also:
        Constant Field Values
      • maxStreamSize

        private int maxStreamSize
        The maximum size of array to allocate. Attempts to allocate larger arrays will result in an exception.
    • Constructor Detail

      • MemoryLimitsAwareOutputStream

        public MemoryLimitsAwareOutputStream()
        Creates a new byte array output stream. The buffer capacity is initially 32 bytes, though its size increases if necessary.
      • MemoryLimitsAwareOutputStream

        public MemoryLimitsAwareOutputStream​(int size)
        Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.
        Parameters:
        size - the initial size.
        Throws:
        java.lang.IllegalArgumentException - if size is negative.
    • Method Detail

      • getMaxStreamSize

        public long getMaxStreamSize()
        Gets the maximum size which can be occupied by this output stream.
        Returns:
        the maximum size which can be occupied by this output stream.
      • setMaxStreamSize

        public MemoryLimitsAwareOutputStream setMaxStreamSize​(int maxStreamSize)
        Sets the maximum size which can be occupied by this output stream.
        Parameters:
        maxStreamSize - the maximum size which can be occupied by this output stream.
        Returns:
        this MemoryLimitsAwareOutputStream
      • write

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