Class BoundedInputStream

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

    public class BoundedInputStream
    extends java.io.FilterInputStream
    A stream that limits reading from a wrapped stream to a given number of bytes.
    Since:
    1.6
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long count
      The current count of bytes counted.
      private long mark
      The current mark.
      private long maxCount
      The max count of bytes to read.
      private boolean propagateClose
      Flag if close should be propagated.
      • Fields inherited from class java.io.FilterInputStream

        in
    • Constructor Summary

      Constructors 
      Constructor Description
      BoundedInputStream​(java.io.InputStream in, long maxCount)
      Creates the stream that will at most read the given amount of bytes from the given stream.
      BoundedInputStream​(java.io.InputStream in, long maxCount, boolean propagateClose)
      Creates the stream that will at most read the given amount of bytes from the given stream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      long getBytesRead()
      Returns the current number of bytes read from this stream.
      long getBytesRemaining()
      Gets how many bytes remain to read.
      long getMaxCount()
      Gets the max count of bytes to read.
      void mark​(int readLimit)
      int read()  
      int read​(byte[] b, int off, int len)  
      void reset()
      long skip​(long n)
      • Methods inherited from class java.io.FilterInputStream

        available, markSupported, read
      • 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
    • Field Detail

      • count

        private long count
        The current count of bytes counted.
      • maxCount

        private final long maxCount
        The max count of bytes to read.
      • propagateClose

        private final boolean propagateClose
        Flag if close should be propagated.
      • mark

        private long mark
        The current mark.
    • Constructor Detail

      • BoundedInputStream

        public BoundedInputStream​(java.io.InputStream in,
                                  long maxCount)
        Creates the stream that will at most read the given amount of bytes from the given stream.
        Parameters:
        in - the stream to read from
        maxCount - the maximum amount of bytes to read
      • BoundedInputStream

        public BoundedInputStream​(java.io.InputStream in,
                                  long maxCount,
                                  boolean propagateClose)
        Creates the stream that will at most read the given amount of bytes from the given stream.
        Parameters:
        in - the stream to read from
        maxCount - the maximum amount of bytes to read
        propagateClose - true if calling close() propagates to the close() method of the underlying stream or false if it does not.
        Since:
        1.27.1-0
    • Method Detail

      • 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.FilterInputStream
        Throws:
        java.io.IOException
      • getBytesRead

        public long getBytesRead()
        Returns the current number of bytes read from this stream.
        Returns:
        the number of read bytes
        Since:
        1.27.1-0
      • getMaxCount

        public long getMaxCount()
        Gets the max count of bytes to read.
        Returns:
        The max count of bytes to read.
        Since:
        1.27.1-0
      • getBytesRemaining

        public long getBytesRemaining()
        Gets how many bytes remain to read.
        Returns:
        bytes how many bytes remain to read.
        Since:
        1.21
      • read

        public int read()
                 throws java.io.IOException
        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
        Overrides:
        read in class java.io.FilterInputStream
        Throws:
        java.io.IOException
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Overrides:
        skip in class java.io.FilterInputStream
        Throws:
        java.io.IOException
        Since:
        1.20
      • mark

        public void mark​(int readLimit)
        Overrides:
        mark in class java.io.FilterInputStream
        Since:
        1.27.1-0
      • reset

        public void reset()
                   throws java.io.IOException
        Overrides:
        reset in class java.io.FilterInputStream
        Throws:
        java.io.IOException
        Since:
        1.27.1-0