Package org.apache.solr.common.util
Class ResumableInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.solr.common.util.ResumableInputStream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class ResumableInputStream extends InputStream
AnInputStream
that can be resumed when the connection that is driving the input is interrupted.
-
-
Constructor Summary
Constructors Constructor Description ResumableInputStream(InputStream delegate, Function<Long,InputStream> nextInputStreamSupplier)
Create a new ResumableInputStream
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
void
mark(int readlimit)
boolean
markSupported()
int
read()
If an IOException is thrown by the delegate while reading, the delegate will be recreated and the read will be retried once during this read call.int
read(boolean isRetry)
int
read(byte[] b, int off, int len)
If an IOException is thrown by the delegate while reading, the delegate will be recreated and the read will be retried once during this read call.int
read(byte[] b, int off, int len, boolean isRetry)
void
reset()
long
skip(long n)
If an IOException is thrown by the delegate while skipping, the delegate will be recreated from the position being skipped to and the return value will ben
.-
Methods inherited from class java.io.InputStream
nullInputStream, read, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
ResumableInputStream
public ResumableInputStream(InputStream delegate, Function<Long,InputStream> nextInputStreamSupplier)
Create a new ResumableInputStream- Parameters:
delegate
- The originalInputStream
that will be used as a delegatenextInputStreamSupplier
- A function to create the next InputStream given the number of bytes already read. These inputs can, for example, be used to populate the HTTP Range header. If an unsupported input is provided (more bytes than exist), then anull
InputStream
should be returned.
-
-
Method Detail
-
read
public int read() throws IOException
If an IOException is thrown by the delegate while reading, the delegate will be recreated and the read will be retried once during this read call.- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
public int read(boolean isRetry) throws IOException
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException
If an IOException is thrown by the delegate while reading, the delegate will be recreated and the read will be retried once during this read call.- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len, boolean isRetry) throws IOException
- Throws:
IOException
-
skip
public long skip(long n) throws IOException
If an IOException is thrown by the delegate while skipping, the delegate will be recreated from the position being skipped to and the return value will ben
. This may be longer than the remaining number of bytes, and if so the delegate will be set to a NullInputStream.- Overrides:
skip
in classInputStream
- Throws:
IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classInputStream
-
mark
public void mark(int readlimit)
- Overrides:
mark
in classInputStream
-
available
public int available() throws IOException
- Overrides:
available
in classInputStream
- Throws:
IOException
-
reset
public void reset()
- Overrides:
reset
in classInputStream
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
-