org.apache.commons.io.input
Class QueueInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.commons.io.input.QueueInputStream
-
- All Implemented Interfaces:
- Closeable, AutoCloseable
public class QueueInputStream extends InputStream
Simple alternative to JDKPipedInputStream
; queue input stream provides what's written in queue output stream.Example usage:
QueueInputStream inputStream = new QueueInputStream(); QueueOutputStream outputStream = inputStream.newQueueOutputStream(); outputStream.write("hello world".getBytes(UTF_8)); inputStream.read();
Unlike JDK
PipedInputStream
andPipedOutputStream
, 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 anIOException
.- Since:
- 2.9.0
- See Also:
-
QueueOutputStream
-
Constructor Summary
Constructors Constructor and Description QueueInputStream()
Constructs a new instance with no limit to its internal buffer size.QueueInputStream(BlockingQueue<Integer> blockingQueue)
Constructs a new instance with given buffer
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description QueueOutputStream
newQueueOutputStream()
Creates a new QueueOutputStream instance connected to this.int
read()
Reads and returns a single byte.Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, read, reset, skip
-
Constructor Detail
QueueInputStream
public QueueInputStream()
Constructs a new instance with no limit to its internal buffer size.
QueueInputStream
public QueueInputStream(BlockingQueue<Integer> blockingQueue)
Constructs a new instance with given buffer- Parameters:
-
blockingQueue
- backing queue for the stream
Method Detail
newQueueOutputStream
public QueueOutputStream newQueueOutputStream()
Creates a new QueueOutputStream instance connected to this. Writes to the output stream will be visible to this input stream.- Returns:
- QueueOutputStream connected to this stream
read
public int read()
Reads and returns a single byte.- Specified by:
-
read
in classInputStream
- Returns:
-
either the byte read or
-1
if the end of the stream has been reached
Copyright © 2002–2021 The Apache Software Foundation. All rights reserved.