Package org.jsoup.internal
Class ControllableInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- org.jsoup.internal.ControllableInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class ControllableInputStream extends java.io.FilterInputStream
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 Modifier and Type Field Description private java.io.BufferedInputStream
buff
private boolean
capped
private int
contentLength
private boolean
interrupted
private int
markPos
private int
maxSize
private Progress<?>
progress
private java.lang.Object
progressContext
private int
readPos
private int
remaining
private long
startTime
private long
timeout
-
Constructor Summary
Constructors Modifier Constructor Description private
ControllableInputStream(java.io.BufferedInputStream in, int maxSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
emitProgress()
private boolean
expired()
java.io.BufferedInputStream
inputStream()
void
mark(int readlimit)
<ProgressContext>
ControllableInputStreamonProgress(int contentLength, Progress<ProgressContext> callback, ProgressContext context)
int
read(byte[] b, int off, int len)
static java.nio.ByteBuffer
readToByteBuffer(java.io.InputStream in, int max)
Reads this inputstream to a ByteBuffer.void
reset()
ControllableInputStream
timeout(long startTimeNanos, long timeoutMillis)
static ControllableInputStream
wrap(java.io.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, close, markSupported, read, read, skip
-
-
-
-
Field Detail
-
buff
private final java.io.BufferedInputStream buff
-
capped
private final boolean capped
-
maxSize
private final int maxSize
-
startTime
private long startTime
-
timeout
private long timeout
-
remaining
private int remaining
-
markPos
private int markPos
-
interrupted
private boolean interrupted
-
progress
private Progress<?> progress
-
progressContext
private java.lang.Object progressContext
-
contentLength
private int contentLength
-
readPos
private int readPos
-
-
Method Detail
-
wrap
public static ControllableInputStream wrap(java.io.InputStream in, int bufferSize, int maxSize)
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
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
readToByteBuffer
public static java.nio.ByteBuffer readToByteBuffer(java.io.InputStream in, int max) throws java.io.IOException
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:
java.io.IOException
-
reset
public void reset() throws java.io.IOException
- Overrides:
reset
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
mark
public void mark(int readlimit)
- Overrides:
mark
in classjava.io.FilterInputStream
-
timeout
public ControllableInputStream timeout(long startTimeNanos, long timeoutMillis)
-
emitProgress
private void emitProgress()
-
onProgress
public <ProgressContext> ControllableInputStream onProgress(int contentLength, Progress<ProgressContext> callback, ProgressContext context)
-
expired
private boolean expired()
-
inputStream
public java.io.BufferedInputStream inputStream()
-
-