/* 
	A simple class to send the output
	of one class to the input of another
	class.

	Uses a 256 byte buffer.  Can be changed
		for performance in different types
		of apps or different types of networks.
*/

import java.io.*;

public class StreamCopier {
	private static final int BUF_SIZE = 256;

	//self test 
	public static void main (String[] args) {
		try {

			copy (System.in, System.out);
		}
		catch (IOException ie) {
			System.err.println(ie);
		}
	}

	public static void copy (InputStream in, OutputStream out)
	 throws IOException {

		synchronized (in) {
			synchronized (out) {

				byte[] buffer = new byte [BUF_SIZE];
				while (true) {
					int bytesRead = in.read (buffer);
					if (bytesRead == -1) break;
					out.write(buffer, 0, bytesRead);
				}
			}
		}
	}
}

