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

public Class NonBlockingInputStreamImpl

extends NonBlockingInputStream
Class Inheritance
Imports
java.io.IOException, .InputStream, .InterruptedIOException

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

Field Summary

Modifier and TypeField and Description
private int
b

private IOException
private InputStream
private String
private Thread
private long
private boolean
Inherited from jdk.internal.org.jline.utils.NonBlockingInputStream:
EOFREAD_EXPIRED

Constructor Summary

AccessConstructor and Description
public
NonBlockingInputStreamImpl(String
The stream name
name
,
InputStream
The reader to wrap
in
)

Creates a NonBlockingReader out of a normal blocking reader.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

public synchronized int

Returns:

The byte 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
trueif the byte read must not be consumed
isPeek
)

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

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

private void
run()

public synchronized void
shutdown()

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

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

private synchronized void
Inherited from jdk.internal.org.jline.utils.NonBlockingInputStream:
peekreadreadreadreadBufferedreadBufferedreadBuffered

Field Detail

bback to summary
private int b
exceptionback to summary
private IOException exception
inback to summary
private InputStream in
nameback to summary
private String name
threadback to summary
private Thread thread
threadDelayback to summary
private long threadDelay
threadIsReadingback to summary
private boolean threadIsReading

Constructor Detail

NonBlockingInputStreamImplback to summary
public NonBlockingInputStreamImpl(String name, InputStream 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 stream name

in:InputStream

The reader to wrap

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.InputStream.close.

Closes this input stream and releases any system resources associated with the stream.

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

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

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

Parameters
timeout:long

The amount of time to wait for the character

isPeek:boolean

trueif the byte read must not be consumed

Returns:int

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

Exceptions
IOException:
if anything wrong happens
runback to summary
private void run()
shutdownback to summary
public synchronized void shutdown()

Overrides jdk.internal.org.jline.utils.NonBlockingInputStream.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()