Pipe


Pipe java.nio.channels

Java 1.4

A pipe is an abstraction that allows the one-way transfer of bytes from one thread to another. A pipe has a "read end" and a "write end" which are represented by objects that implement the ReadableByteChannel and WritableByteChannel interfaces. Create a new pipe with the static Pipe. open ( ) method. Call the sink( ) method to obtain the Pipe.SinkChannel object that represents the write end of the pipe, and call the source( ) method to obtain the Pipe.SourceChannel object that represents the read end of the pipe.

Programmers familiar with Unix-style pipes may find the names and return values of the sink( ) and source( ) methods confusing. A Unix pipe is an interprocess communication mechanism that is tied to two specific processes, one of which is a source of bytes and one of which is a destination, or sink, for those bytes. With this conceptual model of a pipe, you would expect the source to obtain the channel it writes to with the source( ) method and the sink to obtain the channel it reads from with the sink( ) method.

This Pipe class is not a Unix-style pipe, however. While it can be used for communication between two threads, the ends of the pipe are not tied to those threads, and there need not be a single source thread and a single sink thread. Therefore, in the Pipe API it is the pipe itself that serves as the source and the sink of bytes: bytes are read from the source end of the pipe, and are written to the sink end.

 public abstract class  Pipe  {  // Protected Constructors  protected  Pipe  ( );  // Nested Types  public abstract static class  SinkChannel  extends java.nio.channels.spi.         AbstractSelectableChannel implements GatheringByteChannel,          WritableByteChannel;       public abstract static class  SourceChannel  extends java.nio.channels.spi.         AbstractSelectableChannel implements ReadableByteChannel,          ScatteringByteChannel;  // Public Class Methods  public static Pipe  open  ( ) throws java.io.IOException;  // Public Instance Methods  public abstract Pipe.SinkChannel  sink  ( );        public abstract Pipe.SourceChannel  source  ( );   } 

Returned By

java.nio.channels.spi.SelectorProvider.openPipe( )



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net