Package org.jsoup.internal
Class ConstrainableInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- java.io.BufferedInputStream
-
- org.jsoup.internal.ConstrainableInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public final class ConstrainableInputStream extends java.io.BufferedInputStream
A jsoup internal class (so don't use it as there is no contract API) that enables constraints on an Input Stream, namely a maximum read size, and the ability to Thread.interrupt() the read.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
capped
private static int
DefaultSize
private boolean
interrupted
private int
maxSize
private int
remaining
private long
startTime
private long
timeout
-
Constructor Summary
Constructors Modifier Constructor Description private
ConstrainableInputStream(java.io.InputStream in, int bufferSize, int maxSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
expired()
int
read(byte[] b, int off, int len)
java.nio.ByteBuffer
readToByteBuffer(int max)
Reads this inputstream to a ByteBuffer.void
reset()
ConstrainableInputStream
timeout(long startTimeNanos, long timeoutMillis)
static ConstrainableInputStream
wrap(java.io.InputStream in, int bufferSize, int maxSize)
If this InputStream is not already a ConstrainableInputStream, let it be one.-
Methods inherited from class java.io.BufferedInputStream
available, close, mark, markSupported, read, skip
-
-
-
-
Field Detail
-
DefaultSize
private static final int DefaultSize
- See Also:
- Constant Field Values
-
capped
private final boolean capped
-
maxSize
private final int maxSize
-
startTime
private long startTime
-
timeout
private long timeout
-
remaining
private int remaining
-
interrupted
private boolean interrupted
-
-
Method Detail
-
wrap
public static ConstrainableInputStream wrap(java.io.InputStream in, int bufferSize, int maxSize)
If this InputStream is not already a ConstrainableInputStream, 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 constrainable input stream
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.BufferedInputStream
- Throws:
java.io.IOException
-
readToByteBuffer
public java.nio.ByteBuffer readToByteBuffer(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.BufferedInputStream
- Throws:
java.io.IOException
-
timeout
public ConstrainableInputStream timeout(long startTimeNanos, long timeoutMillis)
-
expired
private boolean expired()
-
-