verinec.util
Class AbstractProgramExec.StreamGobbler
java.lang.Object
java.lang.Thread
verinec.util.AbstractProgramExec.StreamGobbler
- All Implemented Interfaces:
- Runnable
- Enclosing class:
- AbstractProgramExec
public static class AbstractProgramExec.StreamGobbler
- extends Thread
Class to read the input stream asynchonously.
(This avoids blocking program execution on poorly designed system that have no proper output buffering.)
Helper methods for runtime.exec inspired by
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
- Author:
- David Buchmann, Michael Daconta
|
Method Summary |
void |
run()
Reads the input stream (program output) until the stream is finished
and writes it to the output stream, then exits the thread. |
| Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
is
private InputStream is
os
private OutputStream os
AbstractProgramExec.StreamGobbler
AbstractProgramExec.StreamGobbler(InputStream is,
OutputStream os)
- Instantiate with a stream to be read and a stream to write output into.
If os is null, the program output is simply discarded.
- Parameters:
is - The input to this class (thus the output of the process).os - The stream to take the program output or null to ignore output.
run
public void run()
- Reads the input stream (program output) until the stream is finished
and writes it to the output stream, then exits the thread.
If there is an IOException during reading, the exception is ignored
and the thread finishes.
- Specified by:
run in interface Runnable- Overrides:
run in class Thread