Package org.scijava.util
Class ReadInto
- java.lang.Object
-
- java.lang.Thread
-
- org.scijava.util.ReadInto
-
- All Implemented Interfaces:
Runnable
public class ReadInto extends Thread
This class takes anInputStreamand either accumulates the read bytes in aStringor outputs to aPrintStream.Its intended use is to catch the output and error streams of
Processinstances.- Author:
- Johannes Schindelin
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
Fields Modifier and Type Field Description protected StringBuilderbufferprotected booleancloseOnEOFprotected booleandoneprotected PrintStreamoutprotected BufferedReaderreader-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description ReadInto(InputStream in, PrintStream out)Construct a ReadInto thread and start it right away.ReadInto(InputStream in, PrintStream out, boolean closeOnEOF)Construct a ReadInto thread and start it right away.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddone()voidinterrupt()voidrun()The main method.StringtoString()Return the output as aStringunless aPrintStreamwas specified in the constructor.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield
-
-
-
-
Field Detail
-
reader
protected BufferedReader reader
-
out
protected PrintStream out
-
buffer
protected StringBuilder buffer
-
done
protected boolean done
-
closeOnEOF
protected boolean closeOnEOF
-
-
Constructor Detail
-
ReadInto
public ReadInto(InputStream in, PrintStream out)
Construct a ReadInto thread and start it right away.- Parameters:
in- the stream to readout- the stream to print to; if it is null, thetoString()method will have the output instead
-
ReadInto
public ReadInto(InputStream in, PrintStream out, boolean closeOnEOF)
Construct a ReadInto thread and start it right away.- Parameters:
in- the stream to readout- the stream to print to; if it is null, thetoString()method will have the output instead
-
-
Method Detail
-
run
public void run()
The main method.It runs until interrupted, or until the
InputStreamends, whichever comes first.
-
done
public void done() throws IOException- Throws:
IOException
-
toString
public String toString()
Return the output as aStringunless aPrintStreamwas specified in the constructor.
-
-