• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

PipeReader and PipeWriter

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Although I read lots of tutprials about PipeReader and PipeWriter, I could not exactly understand its purpose and especially usage.
Would you explain it and send sample explanatory code snippet for this ??

Thanks
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pipes are used to channel the output from one thread into the input of another


The Java Tutorial: IO: How to Use Pipe Streams
There's an example on that page as well. Does that all make sense?
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens when you want to read in a InputStream (or Reader) every byte (or character) that is being written to an OutputStream (or Writer)?

That's what pipes are good for. You have one thread procesing information, and writing that information into a PipeOutputStream (PipedWriter). At the other side of the pipe there is another thread, reading the information through a PipedInputStream (PipedReader).

For instance, you have this thread, that simply receives a list of
Strings, reverse them and then prints them on the screen.



Now, instead of printing them in the screen, we are going to send them on pipe
to other thread

You do that like this:



But, how do we connect the pipes?. That's to say, how do we make another thread to
receive the reversed strings. Well, take a look at this example. In this case, the
thread that connects to the other end of the pipe is the main thread.



I hope this helps!
[ April 27, 2006: Message edited by: Edwin Dalorzo ]
 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic