{"id":6329,"date":"2024-08-12T11:01:05","date_gmt":"2024-08-12T03:01:05","guid":{"rendered":""},"modified":"2024-08-12T11:01:05","modified_gmt":"2024-08-12T03:01:05","slug":"\u7ba1\u9053pipe\u662f\u4ec0\u4e48\u610f\u601d_\u7ba1\u9053\u6e05\u7406\u673a\u600e\u4e48\u4f7f\u7528","status":"publish","type":"post","link":"https:\/\/mushiming.com\/6329.html","title":{"rendered":"\u7ba1\u9053pipe\u662f\u4ec0\u4e48\u610f\u601d_\u7ba1\u9053\u6e05\u7406\u673a\u600e\u4e48\u4f7f\u7528"},"content":{"rendered":"
\u4e24\u4e2a\u7ebf\u7a0b\u4e4b\u95f4\u5355\u5411\u4f20\u9012\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u7ba1\u9053Pipe\u89c4\u8303\u8bfb\u5199\u64cd\u4f5c <\/pre>\n<\/p>\n
public static void testPipe() throws IOException { \/\/\u521b\u5efa\u7ba1\u9053 Pipe pipe = Pipe.open(); ByteBuffer buf = ByteBuffer.allocate(1024); \/\/\u901a\u8fc7SinkChannel\uff0c\u5411Pipe\u4e2d\u5199\u6570\u636e Pipe.SinkChannel sinkChannel = pipe.sink(); buf.put(\"helloworld\".getBytes()); buf.flip(); sinkChannel.write(buf); \/\/ \u901a\u8fc7SourceChannel\uff0c\u4ecePipe\u4e2d\u8bfb\u53d6\u6570\u636e Pipe.SourceChannel sourceChannel = pipe.source(); ByteBuffer buf1 = ByteBuffer.allocate(1024); int len = sourceChannel.read(buf1); System.out.println(\"hello:\"+new String(buf1.array(), 0, len)); sourceChannel.close(); sinkChannel.close(); }<\/pre>\n\u770b\u4e66\u4e0a\u7684\u8303\u4f8b\uff0cPipe\u8bfb\u53d6\u6570\u636e\u7684\u65f6\u5019\uff0c\u4e5f\u662f\u4f7f\u7528\u7684buf\u63a5\u6536\uff0c\u6709\u70b9\u6df7\u6dc6\uff0c\u65b0\u5efa\u4e00\u4e2abuf1\u63a5\u6536 \u597d\u7406\u89e3\u70b9<\/p>\n","protected":false},"excerpt":{"rendered":"\u7ba1\u9053pipe\u662f\u4ec0\u4e48\u610f\u601d_\u7ba1\u9053\u6e05\u7406\u673a\u600e\u4e48\u4f7f\u7528\u4e24\u4e2a\u7ebf\u7a0b\u4e4b\u95f4\u5355\u5411\u4f20\u9012\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u7ba1\u9053Pipe\u89c4\u8303\u8bfb\u5199\u64cd\u4f5cpublicstaticvoidtestPipe...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6329"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=6329"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6329\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=6329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=6329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=6329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}