org.vizzini.util
Class StreamGobbler

java.lang.Object
  extended by java.lang.Thread
      extended by org.vizzini.util.StreamGobbler
All Implemented Interfaces:
Runnable

 class StreamGobbler
extends Thread

Provides a stream gobbler. Typical usage is to drain the error and output streams when using Runtime.exec().

   Process process = Runtime.getRuntime().exec(command);

   StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR", false);
   StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), "OUTPUT", false);

   errorGobbler.start();
   outputGobbler.start();

   try
   {
       process.waitFor();
   }
   catch (InterruptedException e)
   {
       LOGGER.log(Level.SEVERE, e.getMessage(), e);
   }
 

Since:
v0.3
Version:
v0.3
Author:
Jeffrey M. Thompson

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
StreamGobbler(InputStream inputStream, String type, boolean isVerbose)
          Construct this object with the given parameters.
 
Method Summary
 boolean isOutputProduced()
           
 void run()
          Run this 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
 

Constructor Detail

StreamGobbler

StreamGobbler(InputStream inputStream,
              String type,
              boolean isVerbose)
Construct this object with the given parameters.

Parameters:
inputStream - Input stream.
type - Stream type.
isVerbose - Flag indicating whether to produce verbose output.
Since:
v0.3
Method Detail

isOutputProduced

public boolean isOutputProduced()
Returns:
Return isOutputProduced.
Since:
v0.3

run

public void run()
Run this thread.

Specified by:
run in interface Runnable
Overrides:
run in class Thread
Since:
v0.3


Copyright 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02