Package de.tsl2.nano.util
Class PipeReader
java.lang.Object
de.tsl2.nano.util.PipeReader
- All Implemented Interfaces:
Runnable
Piped Stream connector. Is able to connect one or two streams with a pipe. For further informations, see
The standard one will write to the given output-stream, reading input from a print-stream (see
The more complicated use case will create two threads. one to read from given input and writing to the pipe, the second reading the pipe and writing to the given output. usefull for en-decodings. WARNING: be sure, your output stream doesn't write again to the printstream - this would be done inside the same thread with a deadlock.
PipedInputStream and PipedOutputStream. Use readInThreads(InputStream, OutputStream) to let
it do the whole work.
Their are two use cases: The standard one will write to the given output-stream, reading input from a print-stream (see
getPrintStream() - creating one new thread. You should connect the print-stream to the desired instance
(like System.out).The more complicated use case will create two threads. one to read from given input and writing to the pipe, the second reading the pipe and writing to the given output. usefull for en-decodings. WARNING: be sure, your output stream doesn't write again to the printstream - this would be done inside the same thread with a deadlock.
- Version:
- $Revision$
- Author:
- Thomas Schneider
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected PipedOutputStreamgetPrintStreamstatic PrintStreamreadInThreads(InputStream in, OutputStream out) creates a PipeReader starting one (if in is null) or two threads to connect the streams through a pipe.voidrun()
-
Constructor Details
-
PipeReader
constructor- Parameters:
in- (optional) input stream (not yet anPipedInputStream!) to be connected to the output stream. if null, only a pipe from to the output-stream will be set.po- output stream (not yet anPipedOutputStream!) to be connected to the input stream.
-
-
Method Details
-
getPrintStream
getPrintStream- Returns:
- printstream, connected to the pipe. if you didn't give an input stream you should connect this printstream to an instance (e.g. System.out).
-
getConnectionPipe
-
run
public void run() -
readInThreads
creates a PipeReader starting one (if in is null) or two threads to connect the streams through a pipe.- Parameters:
in- (optional) input stream (not yet anPipedInputStream!) to be connected to the output stream. if null, only a pipe from to the output-stream will be set.po- output stream (not yet anPipedOutputStream!) to be connected to the input stream.- Returns:
- a printstream that may be set to an output stream (e.g. System.out or/and System.err). makes sense if you don't give any input stream.
-