Code example for PipedOutputStream

Methods: connect

0
package com.chen.crawler; 
 
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() {
		return pipedIS;