- java.lang.Object
-
- java.io.InputStream
-
- org.jline.utils.NonBlockingInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
NonBlockingInputStreamImpl,NonBlockingPumpInputStream
public abstract class NonBlockingInputStream extends InputStream
Non blocking input stream
-
-
Field Summary
Fields Modifier and Type Field Description static intEOFstatic intREAD_EXPIRED
-
Constructor Summary
Constructors Constructor Description NonBlockingInputStream()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intpeek(long timeout)Peeks to see if there is a byte waiting in the input stream without actually consuming the byte.intread()Reads the next byte of data from the input stream.intread(byte[] b, int off, int len)intread(long timeout)Attempts to read a character from the input stream for a specific period of time.abstract intread(long timeout, boolean isPeek)intreadBuffered(byte[] b)voidshutdown()Shuts down the thread that is handling blocking I/O if any.-
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
-
-
-
Field Detail
-
EOF
public static final int EOF
- See Also:
- Constant Field Values
-
READ_EXPIRED
public static final int READ_EXPIRED
- See Also:
- Constant Field Values
-
-
Method Detail
-
read
public int read() throws IOExceptionReads the next byte of data from the input stream. The value byte is returned as anintin the range0to255. If no byte is available because the end of the stream has been reached, the value-1is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.- Specified by:
readin classInputStream- Returns:
- the next byte of data, or
-1if the end of the stream is reached. - Throws:
IOException- if an I/O error occurs.
-
peek
public int peek(long timeout) throws IOExceptionPeeks to see if there is a byte waiting in the input stream without actually consuming the byte.- Parameters:
timeout- The amount of time to wait, 0 == forever- Returns:
- -1 on eof, -2 if the timeout expired with no available input or the character that was read (without consuming it).
- Throws:
IOException- if an I/O error occurs.
-
read
public int read(long timeout) throws IOExceptionAttempts to read a character from the input stream for a specific period of time.- Parameters:
timeout- The amount of time to wait for the character- Returns:
- The character read, -1 if EOF is reached, or -2 if the read timed out.
- Throws:
IOException- if an I/O error occurs.
-
read
public int read(byte[] b, int off, int len) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
readBuffered
public int readBuffered(byte[] b) throws IOException- Throws:
IOException
-
shutdown
public void shutdown()
Shuts down the thread that is handling blocking I/O if any. Note that if the thread is currently blocked waiting for I/O it may not actually shut down until the I/O is received.
-
read
public abstract int read(long timeout, boolean isPeek) throws IOException- Throws:
IOException
-
-