Class IdleTimeoutInputStream

java.lang.Object
java.io.InputStream
org.dellroad.stuff.io.IdleTimeoutInputStream
All Implemented Interfaces:
Closeable, AutoCloseable, AsyncInputStream.Listener

public class IdleTimeoutInputStream extends InputStream implements AsyncInputStream.Listener
Wraps an InputStream and enforces a maximum time limit on how long any read() operation may block. If the time limit is exceeded, an IdleTimeoutException is thrown.

As a side effect of its design, this class may also be used to artificially inject data, EOF, or exceptions into the InputStream, using the AsyncInputStream.Listener interface methods.

This class may also be used to allow testing the real-time state of an InputStream without actually reading from it, via checkConnection(), which guarantees an immediate exception will be thrown if the underlying InputStream has been closed, reached EOF, or itself thrown an exception.

All methods in this class are thread safe.