|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
jline.internal.NonBlockingInputStream
public class 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.
Constructor Summary | |
---|---|
NonBlockingInputStream(InputStream in,
boolean isNonBlockingEnabled)
Creates a NonBlockingInputStream out of a normal blocking
stream. |
Method Summary | |
---|---|
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. |
Methods inherited from class java.io.InputStream |
---|
available, mark, markSupported, read, reset, skip |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NonBlockingInputStream(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.Method Detail |
---|
public void shutdown()
isNonBlockingEnabled()
to return false.
public boolean isNonBlockingEnabled()
public void close() throws IOException
close
in interface Closeable
close
in class InputStream
IOException
public int read() throws IOException
read
in class InputStream
IOException
public int peek(long timeout) throws IOException
timeout
- The amount of time to wait, 0 == forever
IOException
public int read(long timeout) throws IOException
timeout
- The amount of time to wait for the character
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
public void run()
run
in interface Runnable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |