OpenNMS API 1.2.3

org.opennms.netmgt.utils
Class StreamGobbler

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.opennms.netmgt.utils.StreamGobbler
All Implemented Interfaces:
java.lang.Runnable

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.

Version:
CVS $Id: StreamGobbler.java,v 1.5 2004/11/21 03:31:19 brozow Exp $
Author:
Scott McCrory .

Field Summary
private static java.lang.String CLASS_NAME
          The name of this class for logging *
private  java.io.InputStream in
          The input stream we're gobbling *
private  java.io.PrintWriter pwOut
          The printwriter we'll send the gobbled characters to if asked*
private  boolean quit
          Our flag to allow us to safely terminate the monitoring thread *
private static java.lang.String VERSION
          The version of this class (filled in by CVS) *
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
StreamGobbler()
          Basic constructor for StreamGobbler.
StreamGobbler(java.io.InputStream in)
          A simpler constructor for StreamGobbler - defaults to stdout.
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
 java.lang.Object clone()
          We override the clone method here to prevent cloning of our class.
 void quit()
          Tells the StreamGobbler to quit it's operation.
private  void readObject(java.io.ObjectInputStream in)
          We override the readObject method here to prevent deserialization of our class for security reasons.
 void run()
          Gobbles up all the stuff coming from the InputStream and sends it to the OutputStream specified during object construction.
private  void writeObject(java.io.ObjectOutputStream out)
          We override the writeObject method here to prevent serialization of our class for security reasons.
 
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, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

in

private java.io.InputStream in
The input stream we're gobbling *


pwOut

private java.io.PrintWriter pwOut
The printwriter we'll send the gobbled characters to if asked*


quit

private boolean quit
Our flag to allow us to safely terminate the monitoring thread *


CLASS_NAME

private static final java.lang.String CLASS_NAME
The name of this class for logging *

See Also:
Constant Field Values

VERSION

private static final java.lang.String VERSION
The version of this class (filled in by CVS) *

See Also:
Constant Field Values
Constructor Detail

StreamGobbler

public StreamGobbler()
Basic constructor for StreamGobbler.


StreamGobbler

public StreamGobbler(java.io.InputStream in)
A simpler constructor for StreamGobbler - defaults to stdout.

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 - InputStream
out - 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 - InputStream
pwOut - PrintWriter
Method Detail

clone

public final java.lang.Object clone()
                             throws java.lang.CloneNotSupportedException
We override the clone method here to prevent cloning of our class.

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 semophore checked in the main wait loop instead of possibly forcing semaphores to untimely unlock.


readObject

private final void readObject(java.io.ObjectInputStream in)
                       throws java.io.IOException
We override the readObject method here to prevent deserialization of our class for security reasons.

Parameters:
in - java.io.ObjectInputStream
Throws:
java.io.IOException - thrown if a problem occurs

run

public void run()
Gobbles up all the stuff coming from the InputStream and sends it to the OutputStream specified during object construction.


writeObject

private final void writeObject(java.io.ObjectOutputStream out)
                        throws java.io.IOException
We override the writeObject method here to prevent serialization of our class for security reasons.

Parameters:
out - java.io.ObjectOutputStream
Throws:
java.io.IOException - thrown if a problem occurs

OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.