Class StreamChunkCreator.SubRangeInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable
    Direct Known Subclasses:
    StreamChunkCreator.DuplicatedSubRangeInputStream
    Enclosing class:
    StreamChunkCreator

    public static class StreamChunkCreator.SubRangeInputStream
    extends InputStream
    Creates a new SubRangeInputStream that represents a sub-range of bytes from another InputStream.

    It’s assumed the sub range stream can only be read once, and a sub range of bytes from another input stream.

    Note: The behavior is a bit strange. A StreamChunkCreator.SubRangeInputStream doesn't guarantee that, if you read the chunks out of order, it will actually read the designated subrange. All it guarantees is that if you read all of the subranges, you have the entire source stream.

    For example, if you have the stream "AABB" with a chunk size of 2. chunk1 corresponds to [0,1) and chunk2 corresponds to [2,3). If you read chunk2 first, you will get "AA" and not "BB". But if you read both chunks, in any order, and you concatenate the results, you will get "AABB".

    Because this stream cannot be duplicated for each thread, it does not support InputStream.mark(int) and InputStream.reset(), even if the source stream does. This is because all threads share the same stream, and resetting the stream in one thread would interfere with another thread reading from the stream.