/** * Creates a stream pumper to copy the given input stream to the * given output stream. Used for standard input. */ protected StreamPumper createInputPump(final InputStream in, final OutputStream out, final boolean closeWhenExhausted) { assert in != null; assert out != null; StreamPumper pumper = new StreamPumper(in, out, closeWhenExhausted); pumper.setAutoFlush(true); return pumper; } }
/** * This method blocks until the stream pumper finishes. * * @see #isFinished() */ public synchronized void waitFor() throws InterruptedException { while (!isFinished()) { wait(); } }
/** * Creates a stream pumper to copy the given input stream to the * given output stream. * * @param in The input stream to copy from. * @param out The output stream to copy to. * @param closeWhenExhausted If true close the inputstream. * @return A thread object that does the pumping. */ protected Thread createPump(final InputStream in, final OutputStream out, final boolean closeWhenExhausted) { assert in != null; assert out != null; final Thread result = new Thread(new StreamPumper(in, out, closeWhenExhausted)); result.setDaemon(true); return result; }
/** * Stop pumping the streams. */ public void stop() { if (outputThread != null) { try { outputThread.join(); } catch (InterruptedException e) { // ignore } } if (errorThread != null) { try { errorThread.join(); } catch (InterruptedException e) { // ignore } } if (inputPump != null) { inputPump.stop(); } streams.flush(); }