java.lang.Object | ||
↳ | java.io.InputStream | |
↳ | jline.internal.NonBlockingInputStream |
This class wraps a regular input stream and allows it to appear as if it is non-blocking; that is, reads can be performed against it that timeout if no data is seen for a period of time. This effect is achieved by having a separate thread perform all non-blocking read requests and then waiting on the thread to complete.
VERY IMPORTANT NOTES
shutdown()
method must be called in order to shut down
the thread that handles blocking I/O.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a
NonBlockingInputStream out of a normal blocking
stream. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Non-blocking is considered enabled if the feature is enabled and the
I/O thread has not been shut down.
| |||||||||||
Peeks to see if there is a byte waiting in the input stream without
actually consuming the byte.
| |||||||||||
Attempts to read a character from the input stream for a specific
period of time.
| |||||||||||
This version of read() is very specific to jline's purposes, it
will always always return a single byte at a time, rather than filling
the entire buffer.
| |||||||||||
Shuts down the thread that is handling blocking I/O.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
Creates a NonBlockingInputStream
out of a normal blocking
stream. Note that this call also spawn a separate thread to perform the
blocking I/O on behalf of the thread that is using this class. The
shutdown()
method must be called in order to shut this thread down.
in | The input stream to wrap |
---|---|
isNonBlockingEnabled | If true, then the non-blocking methods
read(long) and peek(long) will be available and,
more importantly, the thread will be started to provide support for the
feature. If false, then this class acts as a clean-passthru for the
underlying I/O stream and provides very little overhead.
|
Non-blocking is considered enabled if the feature is enabled and the I/O thread has not been shut down.
Peeks to see if there is a byte waiting in the input stream without actually consuming the byte.
timeout | The amount of time to wait, 0 == forever |
---|
IOException |
---|
Attempts to read a character from the input stream for a specific period of time.
timeout | The amount of time to wait for the character |
---|
IOException |
---|
This version of read() is very specific to jline's purposes, it will always always return a single byte at a time, rather than filling the entire buffer.
IOException |
---|
Shuts down the thread that is handling blocking I/O. Note that if the
thread is currently blocked waiting for I/O it will not actually
shut down until the I/O is received. Shutting down the I/O thread
does not prevent this class from being used, but causes the
non-blocking methods to fail if called and causes isNonBlockingEnabled()
to return false.