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 TypeMethodDescriptionvoid
allowClose
(boolean allowClose) boolean
Check if the underlying InputStream has been read fully.void
close()
void
mark
(int readlimit) int
max()
Get the max size of this stream (how far at most will be read from the underlying stream)void
max
(int newMax) <ProgressContext>
ControllableInputStreamonProgress
(int contentLength, Progress<ProgressContext> callback, ProgressContext context) int
read
(byte[] b, int off, int len) static ByteBuffer
readToByteBuffer
(InputStream in, int max) Reads this inputstream to a ByteBuffer.void
reset()
timeout
(long startTimeNanos, long timeoutMillis) static ControllableInputStream
wrap
(InputStream in, int maxSize) If this InputStream is not already a ControllableInputStream, let it be one.static ControllableInputStream
wrap
(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, skip
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
Methods 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 -
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:
-
read
in 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:
-
reset
in classFilterInputStream
- Throws:
-
IOException
-
mark
public void mark(int readlimit) - Overrides:
-
mark
in 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:
-
close
in interfaceAutoCloseable
- Specified by:
-
close
in interfaceCloseable
- Overrides:
-
close
in classFilterInputStream
- Throws:
-
IOException
-
timeout
-
onProgress
public <ProgressContext> ControllableInputStream onProgress(int contentLength, Progress<ProgressContext> callback, ProgressContext context) -
inputStream
-