edu.ufl.osg.util
Class StreamGobbler

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--edu.ufl.osg.util.StreamGobbler
All Implemented Interfaces:
java.lang.Runnable

public class StreamGobbler
extends java.lang.Thread

Used to empty output and error buffers when running a Runtime.getRuntime.exec(..) operation.

See this article for original code listing and more information: When Runtime.exec() won't [javaworld.com].

Typically you would use this class in a manner similar to the following:

    Process proc = Runtime.getRuntime().exec(script);
   
    StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
    StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
    
    errorGobbler.start();
    outputGobbler.start();
    
    int exitValue = proc.waitFor();
 


Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
StreamGobbler(java.io.InputStream is, java.lang.String streamType)
           
 
Method Summary
 void run()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StreamGobbler

public StreamGobbler(java.io.InputStream is,
                     java.lang.String streamType)
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread