Package org.apache.commons.compress.utils

# Class BoundedInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.commons.compress.utils.BoundedInputStream

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

public class BoundedInputStream extends FilterInputStream
A stream that limits reading from a wrapped stream to a given number of bytes.

Since:
  1.6
This class is not thread-safe

- ## Field Summary

  ### Fields inherited from class java.io.FilterInputStream

  `in`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BoundedInputStream(InputStream in, long size)`
  Creates the stream that will at most read the given amount of bytes from the given stream.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  `long`
  `getBytesRemaining()`
  `int`
  `read()`
  `int`
  `read(byte[] b, int off, int len)`
  `long`
  `skip(long n)`

  ### Methods inherited from class java.io.FilterInputStream

  `available, mark, markSupported, read, reset`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### BoundedInputStream

    public BoundedInputStream(InputStream in, long size)
    Creates the stream that will at most read the given amount of bytes from the given stream.
    Parameters:
      `in` - the stream to read from
      `size` - the maximum amount of bytes to read

- ## Method Details

  - ### close

    public void close()
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Overrides:
      `close` in class `FilterInputStream`

  - ### getBytesRemaining

    public long getBytesRemaining()
    Returns:
      bytes remaining to read
    Since:
      1.21

  - ### read

    public int read() throws IOException
    Overrides:
      `read` in class `FilterInputStream`
    Throws:
      `IOException`

  - ### read

    public int read(byte[] b, int off, int len) throws IOException
    Overrides:
      `read` in class `FilterInputStream`
    Throws:
      `IOException`

  - ### skip

    public long skip(long n) throws IOException
    Overrides:
      `skip` in class `FilterInputStream`
    Throws:
      `IOException`
    Since:
      1.20