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
An
InputStream that can be resumed when the connection that is driving the input is
interrupted.-
Constructor Summary
ConstructorsConstructorDescriptionResumableInputStream(InputStream delegate, Function<Long, InputStream> nextInputStreamSupplier) Create a new ResumableInputStream -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()voidmark(int readlimit) booleanintread()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.intread(boolean isRetry) intread(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.intread(byte[] b, int off, int len, boolean isRetry) voidreset()longskip(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, skipNBytes, transferTo
-
Constructor Details
-
ResumableInputStream
public ResumableInputStream(InputStream delegate, Function<Long, InputStream> nextInputStreamSupplier) Create a new ResumableInputStream- Parameters:
delegate- The originalInputStreamthat 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 anullInputStreamshould be returned.
-
-
Method Details
-
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.- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Throws:
IOException
-
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.- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Throws:
IOException
-
skip
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:
skipin classInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-
mark
public void mark(int readlimit) - Overrides:
markin classInputStream
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
reset
public void reset()- Overrides:
resetin classInputStream
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-