Package org.dellroad.stuff.io
Class PipedStreams
java.lang.Object
org.dellroad.stuff.io.PipedStreams
A better piped input/output stream pair.
The two ends of the pipe are returned by getInputStream()
and getOutputStream()
.
Both streams are fully thread safe. The aliveness of any particular thread that happens to be the
last writer to the output stream is irrelevant.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
final class
TheInputStream
associated with aPipedStreams
instance.final class
TheOutputStream
associated with aPipedStreams
instance. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Default internal buffer size (8160). -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGet the input side of the pipe.Get the output side of the pipe.
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEDefault internal buffer size (8160).- See Also:
-
-
Constructor Details
-
PipedStreams
public PipedStreams()Constructor. -
PipedStreams
public PipedStreams(int bufsiz) Constructor.- Parameters:
bufsiz
- internal buffer size- Throws:
IllegalArgumentException
- ifbufsiz
is zero or negative
-
-
Method Details
-
getInputStream
Get the input side of the pipe.Regarding the returned
InputStream
:- When the internal buffer is empty, reads block until more data is written to the output side, or the output side is closed.
- If the current thread is interrupted while blocked, an
InterruptedIOException
is thrown.
- Returns:
- input side of the piped stream
-
getOutputStream
Get the output side of the pipe.Regarding the returned
OutputStream
:- When the internal buffer is full, writes block until more data is read from the input side.
- If the current thread is interrupted while blocked, an
InterruptedIOException
is thrown. - After the input side side is closed, trying to write more data will generate an
IOException
.
- Returns:
- output side of the piped stream
-