/** * Flush both output streams. */ public void flush() { Flusher.flush(out); // Only attempt to flush the err stream if we aren't sharing it with out if (!streams.isOutputCombined()) { Flusher.flush(err); } }
/** * Close all streams. */ public void close() throws IOException { Closer.close(in, out); // Only attempt to close the err stream if we aren't sharing it with out if (!streams.isOutputCombined()) { Closer.close(err); } }
/** * Set the output stream by means of which input can be sent to the child. */ public void setChildInputStream(final OutputStream out) { assert out != null; if (streams.in != null) { inputPump = createInputPump(streams.in, out, true); } else { Closer.close(out); } }
@Override public void run() { Flusher.flush(ShellHistory.this); } });
/** * Copy chars from a <code>Reader</code> to a <code>Writer</code>. */ public static void copy(final Reader input, final Writer output) throws IOException { copy(input, output, DEFAULT_BUFFER_SIZE); }
/** * Helper which uses current values from {@link StreamSet#system}. */ public IO() { this(StreamSet.system(), true); }
/** * Create a new stream set as {@link System} is currently configured. */ public static StreamSet system() { return new StreamSet(System.in, System.out, System.err); }
/** * 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; } }
/** * Set the input stream from which to read the standard error of the child. */ public void setChildErrorStream(final InputStream in) { assert in != null; if (streams.err != null) { createChildErrorPump(in, streams.err); } }
/** * Create the pump to handle error output. */ protected void createChildErrorPump(final InputStream in, final OutputStream out) { assert in != null; assert out != null; errorThread = createPump(in, out); }
/** * Register combined streams for the current thread. */ public static void register(final InputStream in, final PrintStream out) { register(in, out, out); }
/** * Returns the currently registered streams. */ public static StreamSet current() { StreamRegistration reg = registration(false); if (reg == null) { return previous; } return reg.streams; }
public void close() { Closer.close(in, out); if (!isOutputCombined()) { Closer.close(err); } }
public void flush() { Flusher.flush(out); if (!isOutputCombined()) { Flusher.flush(err); } }