PipedStreamTestMain
■コード
package hello.java.io;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
public class PipedStreamTestMain {
public static void main(String args[]) throws Exception {
byte[] d = { 0x1, 0x3, 0x5 };
PipedOutputStream out = new PipedOutputStream();
// out と in をつなぐ
PipedInputStream in = new PipedInputStream(out);
// out に書き込み
out.write(d);
// out を閉じる
out.close();
// 読み出し
int c;
// 読み出し側からは普通に読み出せる
while ((c = in.read()) != -1) {
// 受信側のスレッドで1バイトずつ読む
System.out.println("read:" + c);
}
}
}
■実行結果
read:1
read:3
read:5