* Copyright (C) 2010 Robert Futrell
* robert_futrell at users.sourceforge.net
* http://fifesoft.com/rsyntaxtextarea
* This library is distributed under a modified BSD license. See the included
* RSTALanguageSupport.License.txt file for details.
package org.fife.rsta.ac;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
* A class that eats the stdout or stderr of a running <tt>Process</tt> to
public class OutputCollector implements Runnable {
* @param in The input stream.
public OutputCollector(InputStream in) {
* @param in The input stream.
* @param sb The buffer in which to collect the output.
public OutputCollector(InputStream in, StringBuffer sb) {
* @param in The input stream.
* @param collect Whether to actually collect the output in a buffer.
* If this is <code>false</code>, then {@link #getOutput()} will
* return <code>null</code>. This parameter can be used if you want
* to eat, but ignore, stdout or stderr for a process.
public OutputCollector(InputStream in, boolean collect) {
* Returns the output collected from the stream.
public StringBuffer getOutput() {
* Called every time a line is read from the stream. This allows
* subclasses to handle lines differently. They can also call into the
* super implementation if they want to log the lines into the buffer.
* @param line The line read.
* @throws IOException If an IO error occurs.
protected void handleLineRead(String line) throws IOException {
sb.append(line).append('\n');
BufferedReader r = new BufferedReader(new InputStreamReader(in));
while ((line=r.readLine())!=null) {
} catch (IOException ioe) {