Class ControllableInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.jsoup.internal.ControllableInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class ControllableInputStream extends 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.
  • Method Details

    • wrap

      public static ControllableInputStream wrap(InputStream in, int maxSize)
      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

      public static ControllableInputStream wrap(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) 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

      public int read(byte[] b, int off, int len) throws IOException
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • readToByteBuffer

      public static ByteBuffer readToByteBuffer(InputStream in, int max) throws 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:
      IOException
    • reset

      public void reset() throws IOException
      Overrides:
      reset in class FilterInputStream
      Throws:
      IOException
    • mark

      public void mark(int readlimit)
      Overrides:
      mark in class FilterInputStream
    • 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

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterInputStream
      Throws:
      IOException
    • timeout

      public ControllableInputStream timeout(long startTimeNanos, long timeoutMillis)
    • onProgress

      public <ProgressContext> ControllableInputStream onProgress(int contentLength, Progress<ProgressContext> callback, ProgressContext context)
    • inputStream

      public BufferedInputStream inputStream()