package com.itjob.javaadvanced;

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

/**
 * 第3章 Java的高级特性考题
 * 使用管道流进行编程实例管道输出流发送消息“Hello! Amigo.”，管道输入流接收到信息后打印出来
 * 管道输入流(用于进行接收数据)
 * @author AmigoXie
 */
class PipeReceiver implements Runnable {
    private PipedInputStream pis = null;
    public PipeReceiver() { 
        this.pis = new PipedInputStream();
    }
    public void run() { 
        byte b[] = new byte[1024]; 
        int len = 0; 
        try {
        	//  接收数据 
            len = this.pis.read(b); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
        try { 
            this.pis.close(); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
        System.out.println("接收的内容为：" + new String(b, 0, len)); 
    }
    public PipedInputStream getPis() { 
        return pis; 
    } 
}

