FileDocCategorySizeDatePackage
PipeTest.javaAPI DocExample2554Sat May 18 21:55:44 BST 2002com.ronsoft.books.nio.channels

PipeTest

public class PipeTest extends Object
Test Pipe objects using a worker thread. Created April, 2002
author
Ron Hitchens (ron@ronsoft.com)
version
$Id: PipeTest.java,v 1.2 2002/05/19 04:55:45 ron Exp $

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)

		// wrap a channel around stdout
		WritableByteChannel out = Channels.newChannel (System.out);
		// start worker and get read end of channel
		ReadableByteChannel workerChannel = startWorker (10);
		ByteBuffer buffer = ByteBuffer.allocate (100);

		while (workerChannel.read (buffer) >= 0) {
			buffer.flip();
			out.write (buffer);
			buffer.clear();
		}
	
private static java.nio.channels.ReadableByteChannelstartWorker(int reps)

		Pipe pipe = Pipe.open();
		Worker worker = new Worker (pipe.sink(), reps);

		worker.start();

		return (pipe.source());