Class BoundedInputStream

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

    public class BoundedInputStream
    extends java.io.InputStream
    Size-bounded input stream. Adapted from Apache Commons IO. Throws an IOException if the input size limit is exceeded.
    Version:
    2016-11-28
    • Constructor Summary

      Constructors 
      Constructor Description
      BoundedInputStream​(java.io.InputStream in)
      Creates a new unbounded input stream.
      BoundedInputStream​(java.io.InputStream in, long size)
      Creates a new bounded input stream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()  
      long getLimitBytes()
      Returns the maximum number of bytes to return.
      boolean isPropagateClose()
      Indicates whether the close() method should propagate to the underling InputStream.
      void mark​(int readlimit)  
      boolean markSupported()  
      int read()  
      int read​(byte[] b)  
      int read​(byte[] b, int off, int len)  
      void reset()  
      void setPropagateClose​(boolean propagateClose)
      Set whether the close() method should propagate to the underling InputStream.
      long skip​(long n)  
      java.lang.String toString()  
      • Methods inherited from class java.io.InputStream

        nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
      • Methods inherited from class java.lang.Object

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

      • BoundedInputStream

        public BoundedInputStream​(java.io.InputStream in,
                                  long size)
        Creates a new bounded input stream.
        Parameters:
        in - The input stream to wrap.
        size - The maximum number of bytes to return, -1 if no limit.
      • BoundedInputStream

        public BoundedInputStream​(java.io.InputStream in)
        Creates a new unbounded input stream.
        Parameters:
        in - The input stream to wrap.
    • Method Detail

      • getLimitBytes

        public long getLimitBytes()
        Returns the maximum number of bytes to return.
        Returns:
        The maximum number of bytes to return, -1 if no limit.
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Overrides:
        skip in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.InputStream
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • 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.InputStream
        Throws:
        java.io.IOException
      • reset

        public void reset()
                   throws java.io.IOException
        Overrides:
        reset in class java.io.InputStream
        Throws:
        java.io.IOException
      • mark

        public void mark​(int readlimit)
        Overrides:
        mark in class java.io.InputStream
      • markSupported

        public boolean markSupported()
        Overrides:
        markSupported in class java.io.InputStream
      • isPropagateClose

        public boolean isPropagateClose()
        Indicates whether the close() method should propagate to the underling InputStream.
        Returns:
        true if calling close() propagates to the close() method of the underlying stream or false if it does not.
      • setPropagateClose

        public void setPropagateClose​(boolean propagateClose)
        Set whether the close() method should propagate to the underling InputStream.
        Parameters:
        propagateClose - true if calling close() propagates to the close() method of the underlying stream or false if it does not.