- 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
Non blocking reader
-
-
Field Summary
Fields Modifier and Type Field Description static intEOFstatic intREAD_EXPIRED
-
Constructor Summary
Constructors Constructor Description NonBlockingReader()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intavailable()intpeek(long timeout)Peeks to see if there is a byte waiting in the input stream without actually consuming the byte.intread()intread(char[] 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.intread(long timeout)Attempts to read a character from the input stream for a specific period of time.protected abstract intread(long timeout, boolean isPeek)Attempts to read a character from the input stream for a specific period of time.abstract intreadBuffered(char[] b)voidshutdown()Shuts down the thread that is handling blocking I/O.-
Methods inherited from class java.io.Reader
close, mark, markSupported, nullReader, read, read, ready, 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
-
shutdown
public void shutdown()
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.
-
read
public int read() throws IOException- Overrides:
readin classReader- Throws:
IOException
-
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 anything wrong happens
-
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 anything wrong happens
-
read
public int read(char[] b, int off, int len) throws IOExceptionThis 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.- Specified by:
readin classReader- Parameters:
b- the bufferoff- the offset in the bufferlen- the maximum number of chars to read- Throws:
IOException- if anything wrong happens
-
readBuffered
public abstract int readBuffered(char[] b) throws IOException- Throws:
IOException
-
available
public int available()
-
read
protected abstract int read(long timeout, boolean isPeek) 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 characterisPeek-trueif the character read must not be consumed- Returns:
- The character read, -1 if EOF is reached, or -2 if the read timed out.
- Throws:
IOException- if anything wrong happens
-
-