public class NonBlockingInputStream
extends java.io.InputStream
implements java.lang.Runnable
VERY IMPORTANT NOTES
shutdown() method must be called in order to shut down
the thread that handles blocking I/O.
| Constructor and Description |
|---|
NonBlockingInputStream(java.io.InputStream in,
boolean isNonBlockingEnabled)
Creates a
NonBlockingInputStream out of a normal blocking
stream. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
boolean |
isNonBlockingEnabled()
Non-blocking is considered enabled if the feature is enabled and the
I/O thread has not been shut down.
|
int |
peek(long timeout)
Peeks to see if there is a byte waiting in the input stream without
actually consuming the byte.
|
int |
read() |
int |
read(byte[] b,
int off,
int len)
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.
|
int |
read(long timeout)
Attempts to read a character from the input stream for a specific
period of time.
|
void |
run() |
void |
shutdown()
Shuts down the thread that is handling blocking I/O.
|
public NonBlockingInputStream(java.io.InputStream in,
boolean isNonBlockingEnabled)
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 wrapisNonBlockingEnabled - 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.public void shutdown()
isNonBlockingEnabled()
to return false.public boolean isNonBlockingEnabled()
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOExceptionpublic int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int peek(long timeout)
throws java.io.IOException
timeout - The amount of time to wait, 0 == foreverjava.io.IOExceptionpublic int read(long timeout)
throws java.io.IOException
timeout - The amount of time to wait for the characterjava.io.IOExceptionpublic int read(byte[] b,
int off,
int len)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic void run()
run in interface java.lang.RunnableCopyright © 2018. All Rights Reserved.