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
Nested ClassesModifier and TypeClassDescriptionstatic interfacefinal classTheInputStreamassociated with aPipedStreamsinstance.final classTheOutputStreamassociated with aPipedStreamsinstance. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault internal buffer size (8160). -
Constructor Summary
Constructors -
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- ifbufsizis 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
InterruptedIOExceptionis 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
InterruptedIOExceptionis thrown. - After the input side side is closed, trying to write more data will generate an
IOException.
- Returns:
- output side of the piped stream
-