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
AnInputStreamthat 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 intavailable()voidclose()voidmark(int readlimit)booleanmarkSupported()intread()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, transferTo
-
-
-
-
Constructor Detail
-
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 Detail
-
read
public int read() throws IOExceptionIf 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
public int read(boolean isRetry) throws IOException- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOExceptionIf 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
public int read(byte[] b, int off, int len, boolean isRetry) throws IOException- Throws:
IOException
-
skip
public long skip(long n) throws IOExceptionIf 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
public int available() throws IOException- Overrides:
availablein classInputStream- Throws:
IOException
-
reset
public void reset()
- Overrides:
resetin classInputStream
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
-