Pipe用于兩個(gè)線程之間的數(shù)據(jù)傳輸。Pipe有一個(gè)SourceChannel和一個(gè)SinkChannel筋遭,數(shù)據(jù)會(huì)被寫入到SinkChannel拱烁,然后從SourceChannel中讀取暇番。
Pipe
Pipe pipe=Pipe.open();
向pipe寫數(shù)據(jù)档悠,需要訪問(wèn)sink 通道廊鸥。
Pipe.SinkChannel sinkChannel = pipe.sink();
write in Pipe
向Pipe讀取數(shù)據(jù)站粟,需要訪問(wèn)source通道:
Pipe.SourceChannel sourceChannel = pipe.source()黍图;
ByteBuffer buffer?= ByteBuffer.allocate(48);
int bytesRead = sourceChannel.read(buffer)奴烙;