/* * By Dave Makower * Copyright © 1996 by Pencom Web Works, a business unit of Pencom Systems, Inc. * Send inquiries to */ import java.net.*; import java.io.*; public class StreamPump extends Thread { DataInputStream in; PrintStream out; Thread master; public StreamPump(InputStream iStream, OutputStream oStream, Thread m) { super("StreamPump for " + m.getName()); master = m; if (iStream instanceof DataInputStream) { in = (DataInputStream) iStream; } else { in = new DataInputStream(iStream); } if (oStream instanceof PrintStream) { out = (PrintStream) oStream; } else { out = new PrintStream(oStream); } start(); } public void run() { String line; try { while((master != null) && (master.isAlive())) { line = in.readLine(); // FOR DEBUGGING // System.out.println("StreamPump received " + line); // System.out.println("Sending to output stream..."); if (line == null) { throw new IOException("StreamPump got null from readLine()"); } out.println(line); } } catch (IOException e) { // e.printStackTrace(System.err); } finally { if (master != null) { master.resume(); } return; } } }