All pastes #30184 Raw Edit

Something

public text v1 · immutable
#30184 ·published 2005-11-22 01:56 UTC
rendered paste body
//=== Test.java
import java.io.*;

public class Test
{
	protected PipedInputStream		utilIn			= new PipedInputStream();
	protected PipedOutputStream		utilOut			= new PipedOutputStream();
	protected PrintStream			utilOutPrinter	= new PrintStream( utilOut );
	protected BufferedReader		utilInReader	= new BufferedReader( new InputStreamReader( utilIn ) );
	
	public static void main( String[] args ) 
	{
		new Test();
	}
	
	public Test()
	{
		try
		{
			utilIn.connect( utilOut );
			new FeedbackListener( utilInReader ).start();
			new DoStuff( utilOutPrinter ).start();
			new Blah().start();
		}
		catch ( Exception e )
		{
			e.printStackTrace();
		}
	}
	
	
	
	class FeedbackListener extends Thread
	{
		BufferedReader in;
		PrintStream out;
		
		public FeedbackListener( BufferedReader in )
		{
			this.in = in;
		}
		
		public void run()
		{
			System.out.println( "Feedback running" );
			try
			{
				String line;
				while ( ( line = in.readLine() ) != null )
				{
					System.out.println( "PIPED: " + line );
				}
			}
			catch ( IOException ie )
			{
				ie.printStackTrace();
			}
		}
	}
	
	class Blah extends Thread
	{
		public void run()
		{
			while ( true )
			{
				// If this is uncommented, the pipes stay open.
				//utilOutPrinter.println( "." );
				try
				{
					sleep( 10000 );
				}
				catch ( Exception e )
				{
					e.printStackTrace();
				}
			}
		}
	}
}


//=== DoStuff.java

import java.io.*;

public class DoStuff extends Thread
{
	private PrintStream out;
	
	public DoStuff( PrintStream out )
	{
		this.out = out;
	}
	
	public void run()
	{
		out.println( "Do: Blah" );
		// When this is done out is closed.
	}

}