tags:

views:

61

answers:

4

What are use cases of Piped streams? Why just not read data into buffer and then write them out?

A: 

They are usually used for simultaneously reading and writing, usually by two different threads.

(They design is quite bad. You can't switch threads at one end and then have that thread exit without disrupting the pipe.)

Tom Hawtin - tackline
+1  A: 

One advantage of using Piped streams is that they provide stream functionality in our code without compelling us to build new specialized streams.

For e.g. we can use pipes to create simple logging facility for our application.We can send messages to logging facility through ordinaty Printwritter and then it can do whatever processing or buffering is required before sending message off to final destination.

more details refer : http://docstore.mik.ua/orelly/java/exp/ch08_01.htm

YoK
+1  A: 

Pipes in Java IO provides the ability for two threads running in the same JVM to communicate. As such pipes are a common source or destination of data.

This useful if you have two long running Threads and one is setup to produce data and the other consume it.

Romain Hippeau
A: 

As the other answers have said, they are designed for use between threads. In practice they are best avoided. I've used them once in 13 years and I wish I hadn't.

EJP
Can you provide more detail? What went wrong?
Shaman
It was just a ghastly solution. It's 13 years ago so I can't remember the details but I should have been using some kind of a Queue. In fact I think I did in the end.
EJP