verinec.util
Class AbstractProgramExec.StreamGobbler

java.lang.Object
  extended by java.lang.Thread
      extended by 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

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private  InputStream is
           
private  OutputStream os
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AbstractProgramExec.StreamGobbler(InputStream is, OutputStream os)
          Instantiate with a stream to be read and a stream to write output into.
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

is

private InputStream is

os

private OutputStream os
Constructor Detail

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.
Method Detail

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

Copyright © 2005 Verinec, DIUF