@Override
    public int available() throws IOException {
        long bytesRemaining;
        if (currentPosition < requestedOffset)
            bytesRemaining = requestedLength;
        else {
            bytesRemaining =
                (requestedLength + requestedOffset) - currentPosition;
        }

        return (int) Math.min(bytesRemaining, super.available());
    }
Constructs a new InputSubstream so that when callers start reading from
this stream they'll start at the specified offset in the real stream and
after they've read the specified length, this stream will look empty.

@param in
           The input stream to wrap.
@param offset
           The offset, in bytes, into the specified input stream at which
           to start reading data.
@param length
           The length, in bytes, of the specified input stream to return
           through this stream.
@param closeSourceStream
           True if the wrapped InputStream should be closed when this
           InputSubstream is closed.
aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/internal/InputSubstream.java