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.
Modifier and Type | Field and Description |
---|---|
protected long |
currentStartPositionInSource |
protected InputStream |
source |
Constructor and Description |
---|
SubRangeInputStream(InputStream source,
long desiredStartPositionInSource,
long desiredEndPositionInSource,
long currentStartPositionInSource,
boolean closeSource) |
Modifier and Type | Method and Description |
---|---|
int |
available() |
void |
close() |
long |
length()
Returns the length of this stream.
|
int |
read() |
int |
read(byte[] b,
int off,
int len) |
mark, markSupported, read, reset, skip
protected final InputStream source
protected long currentStartPositionInSource
public SubRangeInputStream(InputStream source, long desiredStartPositionInSource, long desiredEndPositionInSource, long currentStartPositionInSource, boolean closeSource)
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
public long length()
Returns the length of this stream.
public int available() throws IOException
available
in class InputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
Copyright © 2016–2024. All rights reserved.