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
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final SimpleBufferedInputprivate intprivate booleanprivate intprivate intprivate Progress<?> private Objectprivate intprivate intprivate longprivate longFields inherited from class java.io.FilterInputStream
in -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateControllableInputStream(SimpleBufferedInput in, int maxSize) -
Method Summary
Modifier and TypeMethodDescriptionvoidallowClose(boolean allowClose) booleanCheck if the underlying InputStream has been read fully.voidclose()private voidprivate booleanexpired()voidmark(int readlimit) booleanintmax()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()voidtimeout(long startTimeNanos, long timeoutMillis) static ControllableInputStreamwrap(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, read, read, skipMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
buff
-
maxSize
private int maxSize -
startTime
private long startTime -
timeout
private long timeout -
remaining
private int remaining -
markPos
private int markPos -
interrupted
private boolean interrupted -
allowClose
private boolean allowClose -
progress
-
progressContext
-
contentLength
private int contentLength -
readPos
private int readPos
-
-
Constructor Details
-
ControllableInputStream
-
-
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) wrapbufferSize- the buffer size to use when readingmaxSize- the maximum size to allow to be read. 0 == infinite.- Returns:
- a controllable input stream
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classFilterInputStream
-
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.
-
resetFullyRead
public void resetFullyRead() -
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
-
emitProgress
private void emitProgress() -
onProgress
public <ProgressContext> ControllableInputStream onProgress(int contentLength, Progress<ProgressContext> callback, ProgressContext context) -
expired
private boolean expired() -
inputStream
-