public class QueueInputStream
extends java.io.InputStream
PipedInputStream; queue input stream provides what's written in queue output stream.
To build an instance, see QueueInputStream.Builder.
Example usage:
QueueInputStream inputStream = new QueueInputStream();
QueueOutputStream outputStream = inputStream.newQueueOutputStream();
outputStream.write("hello world".getBytes(UTF_8));
inputStream.read();
Unlike JDK PipedInputStream and PipedOutputStream, queue input/output streams may be used safely in a single thread or multiple threads.
Also, unlike JDK classes, no special meaning is attached to initial or current thread. Instances can be used longer after initial threads exited.
Closing a QueueInputStream has no effect. The methods in this class can be called after the stream has been closed without generating an
IOException.
QueueOutputStream| Modifier and Type | Class and Description |
|---|---|
static class |
QueueInputStream.Builder
Builds a new
QueueInputStream instance. |
| Modifier and Type | Field and Description |
|---|---|
private java.util.concurrent.BlockingQueue<java.lang.Integer> |
blockingQueue |
private long |
timeoutNanos |
| Modifier | Constructor and Description |
|---|---|
|
QueueInputStream()
Constructs a new instance with no limit to its internal queue size and zero timeout.
|
|
QueueInputStream(java.util.concurrent.BlockingQueue<java.lang.Integer> blockingQueue)
Deprecated.
|
private |
QueueInputStream(java.util.concurrent.BlockingQueue<java.lang.Integer> blockingQueue,
java.time.Duration timeout)
Constructs a new instance with given queue and timeout.
|
| Modifier and Type | Method and Description |
|---|---|
static QueueInputStream.Builder |
builder()
Constructs a new
QueueInputStream.Builder. |
(package private) java.util.concurrent.BlockingQueue<java.lang.Integer> |
getBlockingQueue()
Gets the blocking queue.
|
(package private) java.time.Duration |
getTimeout()
Gets the timeout duration.
|
QueueOutputStream |
newQueueOutputStream()
Constructs a new QueueOutputStream instance connected to this.
|
int |
read()
Reads and returns a single byte.
|
private final java.util.concurrent.BlockingQueue<java.lang.Integer> blockingQueue
private final long timeoutNanos
public QueueInputStream()
@Deprecated public QueueInputStream(java.util.concurrent.BlockingQueue<java.lang.Integer> blockingQueue)
builder(), QueueInputStream.Builder, and QueueInputStream.Builder.get().blockingQueue - backing queue for the stream.private QueueInputStream(java.util.concurrent.BlockingQueue<java.lang.Integer> blockingQueue,
java.time.Duration timeout)
blockingQueue - backing queue for the stream.timeout - how long to wait before giving up when polling the queue.public static QueueInputStream.Builder builder()
QueueInputStream.Builder.QueueInputStream.Builder.java.util.concurrent.BlockingQueue<java.lang.Integer> getBlockingQueue()
java.time.Duration getTimeout()
public QueueOutputStream newQueueOutputStream()
public int read()
read in class java.io.InputStream-1 if a timeout occurs before a queue element is available.java.lang.IllegalStateException - if thread is interrupted while waiting.