Class StreamChunkCreator.SubRangeInputStream
- java.lang.Object
-
- java.io.InputStream
-
- com.oracle.bmc.objectstorage.transfer.internal.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)
andInputStream.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.
-
-
Field Summary
Fields Modifier and Type Field Description protected long
currentStartPositionInSource
protected InputStream
source
-
Constructor Summary
Constructors Constructor Description SubRangeInputStream(InputStream source, long desiredStartPositionInSource, long desiredEndPositionInSource, long currentStartPositionInSource, boolean closeSource)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
long
length()
Returns the length of this stream.int
read()
int
read(byte[] b, int off, int len)
-
Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
-
-
-
Field Detail
-
source
protected final InputStream source
-
currentStartPositionInSource
protected long currentStartPositionInSource
-
-
Constructor Detail
-
SubRangeInputStream
public SubRangeInputStream(InputStream source, long desiredStartPositionInSource, long desiredEndPositionInSource, long currentStartPositionInSource, boolean closeSource)
-
-
Method Detail
-
read
public int read() throws IOException
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
length
public long length()
Returns the length of this stream.- Returns:
- The length in bytes.
-
available
public int available() throws IOException
- Overrides:
available
in classInputStream
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
-