import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

public class PipedStream {

/**
  * @param args
  * @throws IOException
  */
 public static void main(String[] args) throws IOException {

PipedInputStream input = new PipedInputStream();
  PipedOutputStream output = new PipedOutputStream();
  
  input.connect(output);
  
  new Thread(new Input(input)).start();
  new Thread(new Output(output)).start();
  
 }

}

class Input implements Runnable{
 
 private PipedInputStream in;
 Input(PipedInputStream in){
  this.in = in;
 }
 public void run(){
  
  try {
   byte[] buf = new byte[1024];
   int len = in.read(buf);
   
   String s = new String(buf,0,len);
   
   System.out.println("s="+s);
   in.close();
  } catch (Exception e) {
   // TODO: handle exception
  }
  
 }
}

class Output implements Runnable{
 private PipedOutputStream out;
 Output(PipedOutputStream out){
  this.out = out;
 }
 public void run(){
  
  try {
   Thread.sleep(5000);
   out.write("hi,管道来了!".getBytes());
  } catch (Exception e) {
   // TODO: handle exception
  }
 }
}

最新文章

  1. [原]__FILE__宏
  2. Bootstrap~页面的布局
  3. 剑指Offer 两个链表的第一个公共结点
  4. .net环境下ckeditor与ckfinder中文文件链接乱码的问题
  5. 字节的高低位知识,Ascii,GB2312,UNICODE等编码的关系与来历
  6. js实现网页图片延时加载的原理和代码 提高网站打开速度
  7. HTML里面Textarea换行总结
  8. hdu4006 优先队列
  9. 纯css3实现tab选项卡
  10. leetcode[94] Unique Binary Search Trees
  11. 关于textarea的应用--onchage,onpropertychange,oninput
  12. qt中线程的使用方法
  13. 如何使用ILAsm与ILDasm修改.Net exe(dll)文件
  14. tomcat中的线程问题2
  15. FastJson:Json树的CRUD操作方法实现
  16. typeof 与instanceof
  17. centos7下yum安装mariadb
  18. windows 下 redis安装
  19. Matlab警告消息消除
  20. Spring+Mybatis+Dubbo报错java.lang.reflect.MalformedParameterizedTypeException

热门文章

  1. C#程序集系列06,程序集清单,EXE和DLL的区别
  2. 找回 : MobileCoreServices.framework
  3. 转:如何解决“My mac 64-bit”问题
  4. hadoop函数说明图
  5. iptables只允许指定ip地址访问指定端口
  6. VirtualBox 快捷键
  7. 关于SpringCloud微服务架构概念的一点理解
  8. 启明星会议室预定系统Outlook版开始支持Exchange2013与Office365版
  9. django的单元测试框架unittest、覆盖率
  10. mac的cpu处理器个数、核数、超线程