Class NonBlockingReader

java.lang.Object
java.io.Reader
org.jline.utils.NonBlockingReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable
Direct Known Subclasses:
NonBlockingPumpReader, NonBlockingReaderImpl

public abstract class NonBlockingReader extends Reader
A reader that provides non-blocking read operations.

The NonBlockingReader class extends the standard Reader class to provide non-blocking read operations. Unlike standard readers, which block until data is available or the end of the stream is reached, non-blocking readers can be configured to return immediately or after a specified timeout if no data is available.

This class is particularly useful for terminal applications that need to perform other tasks while waiting for user input, or that need to implement features like input timeouts or polling.

The class defines two special return values:

  • EOF (-1) - Indicates that the end of the stream has been reached
  • READ_EXPIRED (-2) - Indicates that the read operation timed out

Implementations of this class typically use a separate thread to handle blocking I/O operations, allowing the main thread to continue execution. The shutdown() method can be used to terminate this background thread when it is no longer needed.