Class BoundedInputStream

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

    public class BoundedInputStream
    extends java.io.InputStream
    Very slight modification of Commons' BoundedInputStream so that we can figure out if this hit the bound or not. This relies on IOUtils' skip and read to try to fully read/skip inputstream.
    • Constructor Summary

      Constructors 
      Constructor Description
      BoundedInputStream​(long max, java.io.InputStream in)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasHitBound()  
      void mark​(int readLimit)  
      int read()  
      int read​(byte[] b)
      Invokes the delegate's read(byte[]) method.
      int read​(byte[] b, int off, int len)
      Invokes the delegate's read(byte[], int, int) method.
      void reset()  
      long skip​(long n)
      Invokes the delegate's skip(long) method.
      • Methods inherited from class java.io.InputStream

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

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BoundedInputStream

        public BoundedInputStream​(long max,
                                  java.io.InputStream in)
    • Method Detail

      • 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
        Invokes the delegate's read(byte[]) method.
        Overrides:
        read in class java.io.InputStream
        Parameters:
        b - the buffer to read the bytes into
        Returns:
        the number of bytes read or -1 if the end of stream or the limit has been reached.
        Throws:
        java.io.IOException - if an I/O error occurs
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Invokes the delegate's read(byte[], int, int) method. This does not have the same guarantees as IOUtil's readFully()...be careful.
        Overrides:
        read in class java.io.InputStream
        Parameters:
        b - the buffer to read the bytes into
        off - The start offset
        len - The number of bytes to read
        Returns:
        the number of bytes read or -1 if the end of stream or the limit has been reached.
        Throws:
        java.io.IOException - if an I/O error occurs
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Invokes the delegate's skip(long) method. As with InputStream generally, this does not guarantee reading n bytes. Use IOUtils' skipFully for that functionality.
        Overrides:
        skip in class java.io.InputStream
        Parameters:
        n - the number of bytes to skip
        Returns:
        the actual number of bytes skipped
        Throws:
        java.io.IOException - if an I/O error occurs
      • 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
      • hasHitBound

        public boolean hasHitBound()