Package org.jsoup.internal
Class ControllableInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.jsoup.internal.ControllableInputStream
- All Implemented Interfaces:
-
Closeable,AutoCloseable
A jsoup internal class (so don't use it as there is no contract API) that enables controls on a buffered input stream, namely a maximum read size, and the ability to Thread.interrupt() the read.
-
Field Summary
Fields inherited from class java.io.FilterInputStream
in -
Method Summary
Modifier and TypeMethodDescriptionvoidallowClose(boolean allowClose) booleanCheck if the underlying InputStream has been read fully.voidclose()voidmark(int readlimit) intmax()Get the max size of this stream (how far at most will be read from the underlying stream)voidmax(int newMax) <ProgressContext>
ControllableInputStreamonProgress(int contentLength, Progress<ProgressContext> callback, ProgressContext context) intread(byte[] b, int off, int len) static ByteBufferreadToByteBuffer(InputStream in, int max) Reads this inputstream to a ByteBuffer.voidreset()timeout(long startTimeNanos, long timeoutMillis) static ControllableInputStreamwrap(@Nullable InputStream in, int maxSize) If this InputStream is not already a ControllableInputStream, let it be one.static ControllableInputStreamwrap(InputStream in, int bufferSize, int maxSize) If this InputStream is not already a ControllableInputStream, let it be one.Methods inherited from class java.io.FilterInputStream
available, markSupported, read, read, skipMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferToMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Method Details
-
wrap
If this InputStream is not already a ControllableInputStream, let it be one.- Parameters:
-
in- the input stream to (maybe) wrap. Anullinput will create an empty wrapped stream. -
maxSize- the maximum size to allow to be read. 0 == infinite. - Returns:
- a controllable input stream
-
wrap
If this InputStream is not already a ControllableInputStream, let it be one.- Parameters:
-
in- the input stream to (maybe) wrap -
bufferSize- the buffer size to use when reading -
maxSize- the maximum size to allow to be read. 0 == infinite. - Returns:
- a controllable input stream
-
read
- Overrides:
-
readin classFilterInputStream - Throws:
-
IOException
-
readToByteBuffer
Reads this inputstream to a ByteBuffer. The supplied max may be less than the inputstream's max, to support reading just the first bytes.- Throws:
-
IOException
-
reset
- Overrides:
-
resetin classFilterInputStream - Throws:
-
IOException
-
mark
public void mark(int readlimit) - Overrides:
-
markin classFilterInputStream
-
baseReadFully
public boolean baseReadFully()Check if the underlying InputStream has been read fully. There may still content in buffers to be consumed, and read methods may return -1 if hit the read limit.- Returns:
- true if the underlying inputstream has been read fully.
-
max
public int max()Get the max size of this stream (how far at most will be read from the underlying stream)- Returns:
- the max size
-
max
public void max(int newMax) -
allowClose
public void allowClose(boolean allowClose) -
close
- Specified by:
-
closein interfaceAutoCloseable - Specified by:
-
closein interfaceCloseable - Overrides:
-
closein classFilterInputStream - Throws:
-
IOException
-
timeout
-
onProgress
public <ProgressContext> ControllableInputStream onProgress(int contentLength, Progress<ProgressContext> callback, ProgressContext context) -
inputStream
-