Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input and Output Stream Pipe in Java

Does anyone have any good suggestions for creating a Pipe object in Java which is both an InputStream and and OutputStream since Java does not have multiple inheritance and both of the streams are abstract classes instead of interfaces?

The underlying need is to have a single object that can be passed to things which need either an InputStream or an OutputStream to pipe output from one thread to input for another.

like image 283
Baginsss Avatar asked Dec 13 '08 06:12

Baginsss


1 Answers

It seems the point of this question is being missed. If I understand you correctly, you want an object that functions like an InputStream in one thread, and an OutputStream in another to create a means of communicating between the two threads.

Perhaps one answer is to use composition instead of inheritance (which is recommended practice anyway). Create a Pipe which contains a PipedInputStream and a PipedOutputStream connected to each other, with getInputStream() and getOutputStream() methods.

You can't directly pass the Pipe object to something needing a stream, but you can pass the return value of it's get methods to do it.

Does that work for you?

like image 96
Lawrence Dol Avatar answered Nov 16 '22 04:11

Lawrence Dol