Class SizeLimitInputStream

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

    public class SizeLimitInputStream
    extends java.io.FilterInputStream
    Stream that only allows a certain number of bytes to be read. Current implementation only tracks read bytes, and ignores any mark or reset calls.
    • Field Summary

      • Fields inherited from class java.io.FilterInputStream

        in
    • Constructor Summary

      Constructors 
      Constructor Description
      SizeLimitInputStream​(java.io.InputStream in, long limit)
      Construct a new SizeLimitInputStream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void checkLimit()
      Check how many bytes have been read.
      long getRead()
      Return number of bytes read.
      int read()
      Read one byte.
      int read​(byte[] b)
      Read into an array of bytes.
      int read​(byte[] b, int off, int len)
      Read into an array of bytes.
      • Methods inherited from class java.io.FilterInputStream

        available, close, mark, markSupported, reset, skip
      • 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, toString, wait, wait, wait
    • Constructor Detail

      • SizeLimitInputStream

        public SizeLimitInputStream​(java.io.InputStream in,
                                    long limit)
        Construct a new SizeLimitInputStream.
        Parameters:
        in - stream to limit.
        limit - maximum number of bytes allowed to read.
    • Method Detail

      • getRead

        public long getRead()
        Return number of bytes read.
        Returns:
        bytes read
      • read

        public int read()
                 throws java.io.IOException
        Read one byte.
        Overrides:
        read in class java.io.FilterInputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b)
                 throws java.io.IOException
        Read into an array of bytes.
        Overrides:
        read in class java.io.FilterInputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Read into an array of bytes.
        Overrides:
        read in class java.io.FilterInputStream
        Throws:
        java.io.IOException
      • checkLimit

        protected void checkLimit()
                           throws java.io.IOException
        Check how many bytes have been read.
        Throws:
        java.io.IOException - if more bytes than the limit allows have been read.