Class TimeoutInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class TimeoutInputStream
    extends FilterInputStream
    Wraps an input stream that blocks indefinitely to simulate timeouts on read(), skip(), and close(). The resulting input stream is buffered and supports retrying operations that failed due to an InterruptedIOException. Supports resuming partially completed operations after an InterruptedIOException REGARDLESS of whether the underlying stream does unless the underlying stream itself generates InterruptedIOExceptions in which case it must also support resuming. Check the bytesTransferred field to determine how much of the operation completed; conversely, at what point to resume.
    Since:
    3.0
    • Constructor Detail

      • TimeoutInputStream

        public TimeoutInputStream​(InputStream in,
                                  int bufferSize,
                                  long readTimeout,
                                  long closeTimeout)
        Creates a timeout wrapper for an input stream.
        Parameters:
        in - the underlying input stream
        bufferSize - the buffer size in bytes; should be large enough to mitigate Thread synchronization and context switching overhead
        readTimeout - the number of milliseconds to block for a read() or skip() before throwing an InterruptedIOException; 0 blocks indefinitely
        closeTimeout - the number of milliseconds to block for a close() before throwing an InterruptedIOException; 0 blocks indefinitely, -1 closes the stream in the background
      • TimeoutInputStream

        public TimeoutInputStream​(InputStream in,
                                  int bufferSize,
                                  long readTimeout,
                                  long closeTimeout,
                                  boolean growWhenFull)