Package org.opennms.core.utils
Class StreamGobbler
- java.lang.Object
-
- java.lang.Thread
-
- org.opennms.core.utils.StreamGobbler
-
- All Implemented Interfaces:
java.lang.Runnable
public class StreamGobbler extends java.lang.Thread
Captures the output of an InputStream.
With acknowledgements to Michael C. Daconta, author of "Java Pitfalls, Time Saving Solutions, and Workarounds to Improve Programs." and his article in JavaWorld "When Runtime.exec() Won't". See the ExecRunner class for a reference implementation.- Author:
- Scott McCrory .
-
-
Constructor Summary
Constructors Constructor Description StreamGobbler()
Basic constructor for StreamGobbler.StreamGobbler(java.io.InputStream in)
A simpler constructor for StreamGobbler - defaults toSystem.out
StreamGobbler(java.io.InputStream in, java.io.OutputStream out)
A more explicit constructor for StreamGobbler where you can tell it exactly where to relay the output to.StreamGobbler(java.io.InputStream in, java.io.PrintWriter pwOut)
A more explicit constructor for StreamGobbler where you can tell it exactly where to relay the output to.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
We override theclone
method here to prevent cloning of our class.void
quit()
Tells the StreamGobbler to quit it's operation.void
run()
Gobbles up all the stuff coming from the InputStream and sends it to the OutputStream specified during object construction.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Constructor Detail
-
StreamGobbler
public StreamGobbler()
Basic constructor for StreamGobbler.
-
StreamGobbler
public StreamGobbler(java.io.InputStream in)
A simpler constructor for StreamGobbler - defaults toSystem.out
- Parameters:
in
- InputStream
-
StreamGobbler
public StreamGobbler(java.io.InputStream in, java.io.OutputStream out)
A more explicit constructor for StreamGobbler where you can tell it exactly where to relay the output to. Creation date: (9/23/2001 8:48:01 PM)- Parameters:
in
- InputStreamout
- OutputStream
-
StreamGobbler
public StreamGobbler(java.io.InputStream in, java.io.PrintWriter pwOut)
A more explicit constructor for StreamGobbler where you can tell it exactly where to relay the output to. Creation date: (9/23/2001 8:48:01 PM)- Parameters:
in
- InputStreampwOut
- PrintWriter
-
-
Method Detail
-
clone
public final java.lang.Object clone() throws java.lang.CloneNotSupportedException
We override theclone
method here to prevent cloning of our class.- Overrides:
clone
in classjava.lang.Thread
- Returns:
- Nothing ever really returned since we throw a CloneNotSupportedException
- Throws:
java.lang.CloneNotSupportedException
- To indicate cloning is not allowed
-
quit
public void quit()
Tells the StreamGobbler to quit it's operation. This is safer than using stop() since it uses a semaphore checked in the main wait loop instead of possibly forcing semaphores to untimely unlock.
-
run
public void run()
Gobbles up all the stuff coming from the InputStream and sends it to the OutputStream specified during object construction.- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
-