Code example for PipedOutputStream

Methods: connect

0
 
import java.io.ByteArrayOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.PipedInputStream; 
import java.io.PipedOutputStream; 
 
public class LoopedStreams  
{ 
    private PipedOutputStream pipedOS=new PipedOutputStream();
    private boolean keepRunning = true;
    private ByteArrayOutputStream byteArrayOS=new ByteArrayOutputStream(){
 
        public void close()  
        { 
            keepRunning = false;
            try { 
                super.close(); 
                pipedOS.close();
            } 
            catch(IOException e) {
 
                // ¼Ç¼´íÎó»òÆäËû´¦Àí 
 
                // Ϊ¼òµ¥¼Æ£¬´Ë´¦ÎÒÃÇÖ±½Ó½áÊø 
                System.exit(1);
            } 
        } 
    }; 
 
    private PipedInputStream pipedIS=new PipedInputStream(){
        public void close()  
        { 
            keepRunning = false;
            try{ 
                super.close(); 
            } 
            catch(IOException e) {
                // ¼Ç¼´íÎó»òÆäËû´¦Àí 
                // Ϊ¼òµ¥¼Æ£¬´Ë´¦ÎÒÃÇÖ±½Ó½áÊø 
                System.exit(1);
            } 
        } 
    }; 
 
    public LoopedStreams()throws IOException 
    { 
        pipedOS.connect(pipedIS);
        startByteArrayReaderThread(); 
    } // LoopedStreams() 
 
    public InputStream getInputStream()
    {