APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.org.jline.utils

public Class NonBlockingReaderImpl

extends NonBlockingReader
Class Inheritance
Imports
java.io.IOException, .InterruptedIOException, .Reader

This class wraps a regular reader 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

Author
Scott C. Gray <[email protected]>
Since
2.7

Field Summary

Modifier and TypeField and Description
private int
private IOException
private Reader
private String
public static final int
private Thread
private long
private boolean
Inherited from jdk.internal.org.jline.utils.NonBlockingReader:
EOF

Constructor Summary

AccessConstructor and Description
public
NonBlockingReaderImpl(String
The reader name
name
,
Reader
The reader to wrap
in
)

Creates a NonBlockingReader out of a normal blocking reader.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
public void
close()

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Closes the stream and releases any system resources associated with it.

protected synchronized int

Returns:

The character read, -1 if EOF is reached, or -2 if the read timed out.
read
(long
The amount of time to wait for the character
timeout
,
boolean isPeek)

Implements abstract jdk.internal.org.jline.utils.NonBlockingReader.read.

Attempts to read a character from the input stream for a specific period of time.

public int
readBuffered(char[] b, int off, int len, long timeout)

Implements abstract jdk.internal.org.jline.utils.NonBlockingReader.readBuffered.

public synchronized boolean
ready()

Overrides java.io.Reader.ready.

Tells whether this stream is ready to be read.

private void
run()

public synchronized void
shutdown()

Overrides jdk.internal.org.jline.utils.NonBlockingReader.shutdown.

Shuts down the thread that is handling blocking I/O.

private synchronized void
Inherited from jdk.internal.org.jline.utils.NonBlockingReader:
availablepeekreadreadreadreadBufferedreadBuffered

Field Detail

chback to summary
private int ch
exceptionback to summary
private IOException exception
inback to summary
private Reader in
nameback to summary
private String name
READ_EXPIREDback to summary
public static final int READ_EXPIRED

Hides jdk.internal.org.jline.utils.NonBlockingReader.READ_EXPIRED.

threadback to summary
private Thread thread
threadDelayback to summary
private long threadDelay
threadIsReadingback to summary
private boolean threadIsReading

Constructor Detail

NonBlockingReaderImplback to summary
public NonBlockingReaderImpl(String name, Reader in)

Creates a NonBlockingReader out of a normal blocking reader. 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.

Parameters
name:String

The reader name

in:Reader

The reader to wrap

Method Detail

clearback to summary
public synchronized void clear() throws IOException
closeback to summary
public void close() throws IOException

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Doc from java.io.Reader.close.

Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
readback to summary
protected synchronized int read(long timeout, boolean isPeek) throws IOException

Implements abstract jdk.internal.org.jline.utils.NonBlockingReader.read.

Attempts to read a character from the input stream for a specific period of time.

Parameters
timeout:long

The amount of time to wait for the character

Returns:int

The character read, -1 if EOF is reached, or -2 if the read timed out.

Exceptions
IOException:

Doc from jdk.internal.org.jline.utils.NonBlockingReader.read.

if anything wrong happens

readBufferedback to summary
public int readBuffered(char[] b, int off, int len, long timeout) throws IOException

Implements abstract jdk.internal.org.jline.utils.NonBlockingReader.readBuffered.

Annotations
@Override
readyback to summary
public synchronized boolean ready() throws IOException

Overrides java.io.Reader.ready.

Doc from java.io.Reader.ready.

Tells whether this stream is ready to be read.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
runback to summary
private void run()
shutdownback to summary
public synchronized void shutdown()

Overrides jdk.internal.org.jline.utils.NonBlockingReader.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.

startReadingThreadIfNeededback to summary
private synchronized void startReadingThreadIfNeeded()