Piped I/O for Threads
A pipe is an easy way to move data between two threads. One thread writes into the pipe, and the other reads from it. This forms a producer/consumer buffer, ready-programmed for you! There are two stream classes that we always use together in a matched consumer/producer pair:
-
PipedInputStream –. Gets bytes from a pipe (think “hosepipe”; it's just a data structure that squirts bytes at you).
-
PipedOutputStream –. Puts bytes into a pipe (think “drainpipe”; it's just a data structure that drinks down bytes that you pour into it).
An object of one of these classes is connected to an object of the other class, providing a safe way (without data race conditions) for one thread to send a stream of data to another thread. ...
Get Just Java™ 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.