Pipe用于兩個線程之間的數(shù)據(jù)傳輸。Pipe有一個SourceChannel和一個SinkChannel,數(shù)據(jù)會被寫入到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);