Pipe用于兩個(gè)線程之間的數(shù)據(jù)傳輸。Pipe有一個(gè)SourceChannel和一個(gè)SinkChannel,數(shù)據(jù)會(huì)被寫入到SinkChannel,然后從SourceChannel中讀取。

Pipe
Pipe pipe=Pipe.open();
向pipe寫數(shù)據(jù),需要訪問sink 通道。
Pipe.SinkChannel sinkChannel = pipe.sink();
write in Pipe
向Pipe讀取數(shù)據(jù),需要訪問source通道:
Pipe.SourceChannel sourceChannel = pipe.source();
ByteBuffer buffer?= ByteBuffer.allocate(48);
int bytesRead = sourceChannel.read(buffer);