Class SubInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class SubInputStream
    extends FilterInputStream
    This class is a FilterInputStream descendant that reads from an underlying InputStream up to a defined number of bytes or the end of the underlying stream. Closing this InputStream will not result in the underlying InputStream to be closed, too.

    This InputStream can be used to read chunks from a larger file of which the length is known in advance.

    • Constructor Detail

      • SubInputStream

        public SubInputStream​(InputStream in,
                              long maxLen,
                              boolean closeUnderlying)
        Creates a new SubInputStream.
        Parameters:
        in - the InputStream to read from
        maxLen - the maximum number of bytes to read from the underlying InputStream until the end-of-file is signalled.
        closeUnderlying - true if the underlying stream should be closed when the close() method is called.
      • SubInputStream

        public SubInputStream​(InputStream in,
                              long maxLen)
        Creates a new SubInputStream. The underlying stream is not closed, when close() is called.
        Parameters:
        in - the InputStream to read from
        maxLen - the maximum number of bytes to read from the underlying InputStream until the end-of-file is signalled.