Use cases of PipedInputStream and PipedOutputStream

What are the options for using streaming streams? Why not just read the data into the buffer and then write it?

+5
java io
source share
5 answers

One of the advantages of using Piped streams is that they provide stream functions in our code, without forcing us to create new custom threads.

For example, we can use feeds to create a simple logging tool for our application. We can send messages to the logger through the ordinaty Printwritter, and then it can do any processing or buffering before sending the message to its final destination.

more detailed information: http://docstore.mik.ua/orelly/java/exp/ch08_01.htm

+1
source share

Pipes in Java IO provide the ability for two threads running in the same JVM. Since such channels are a common source or recipient of data.

This is useful if you have two long Thread threads, one for data creation and one for use.

+3
source share

BlockingQueue or similar collections may serve you better, which is thread safe, reliable and scales better.

+3
source share

They are usually used to read and write at the same time, usually in two different streams.

(They are designed rather poorly. You cannot switch flows from one end and then exit this stream without interrupting it.)

+2
source share

As the other answers said, they are for use between threads. In practice, they are best avoided. I used them once every 13 years, and I'm sorry that I did not.

+2
source share

All Articles