ca.bc.webarts.tools
Class StreamGobbler

java.lang.Object
  extended byjava.lang.Thread
      extended byca.bc.webarts.tools.StreamGobbler
All Implemented Interfaces:
java.lang.Runnable

public class StreamGobbler
extends java.lang.Thread

A simple class to take an input stream and dump it out to the commandline with a prepended string. It is designed to run in its own thread so it can pump the data silently in the background.

Author:
TGutwin

Field Summary
(package private)  boolean aborted_
          the thread aborted flag.
(package private)  boolean capture_
          a control flag that turns on/off the capturing of the input stream
(package private)  java.lang.StringBuffer captureBuffer_
          The buffer used to store the input stream data IFF the capture has been turned on with the capture_ flag.
 boolean finishedGobbling_
          Flag so we can signal the control/signal the threads end.
(package private)  java.lang.String input_
          the input from in stream
(package private)  boolean inputGobbler_
          signals if we are gobbling input instead of the default outputstreams.
(package private)  java.io.InputStream is_
          The class InputStream that gets echoed to the designated output stream (default=System.out).
(package private)  java.lang.String lineSep_
          the lin sep chars
(package private)  java.io.OutputStream os_
          The location of any output.
(package private)  java.io.PrintStream ps_
          The location of any output.
(package private)  java.lang.String type_
          The string to get prepended to the output from the InputStream.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
StreamGobbler(java.io.InputStream inputstream, java.lang.String string)
          A Simple Constructor for the StreamGobbler object that ends up using System.out as the Output PrintStream.
StreamGobbler(java.io.InputStream inputstream, java.lang.String string, java.io.PrintStream os)
          Constructor for the StreamGobbler object that requires all parameters to be spec'd.
StreamGobbler(java.lang.String input, java.io.OutputStream os)
          Constructor for the StreamGobbler object that gobbles input instead of the default outputstreams.
 
Method Summary
 void abort()
           
 boolean getCapture()
          Get Method for class field 'capture_'.
 java.lang.String getCapturedOutput()
          Gets the inputStreams captured data.
 java.io.PrintStream getOs_()
          Get Method for class field 'ps_'.
 void run()
          Main processing method for the StreamGobbler object
 void setCapture(boolean capture)
          Set Method for class field 'capture_'.
 void setOs_(java.io.PrintStream ps_)
          Set Method for class field 'ps_'.
 
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

finishedGobbling_

public boolean finishedGobbling_
Flag so we can signal the control/signal the threads end.


is_

java.io.InputStream is_
The class InputStream that gets echoed to the designated output stream (default=System.out).


ps_

java.io.PrintStream ps_
The location of any output.


os_

java.io.OutputStream os_
The location of any output.


type_

java.lang.String type_
The string to get prepended to the output from the InputStream.


inputGobbler_

boolean inputGobbler_
signals if we are gobbling input instead of the default outputstreams.


lineSep_

java.lang.String lineSep_
the lin sep chars


input_

java.lang.String input_
the input from in stream


aborted_

boolean aborted_
the thread aborted flag.


capture_

boolean capture_
a control flag that turns on/off the capturing of the input stream


captureBuffer_

java.lang.StringBuffer captureBuffer_
The buffer used to store the input stream data IFF the capture has been turned on with the capture_ flag.

Constructor Detail

StreamGobbler

public StreamGobbler(java.io.InputStream inputstream,
                     java.lang.String string)
A Simple Constructor for the StreamGobbler object that ends up using System.out as the Output PrintStream. So it simply dumps the monitored InputStream to System.out.

Parameters:
inputstream - The stream to watch for input.
string - The string to get prepended to the output from the InputStream before it gets pumped into the output PrintStream.

StreamGobbler

public StreamGobbler(java.io.InputStream inputstream,
                     java.lang.String string,
                     java.io.PrintStream os)
Constructor for the StreamGobbler object that requires all parameters to be spec'd.

Parameters:
inputstream - The stream to watch for input.
string - The string to get prepended to the output from the InputStream before it gets pumped into the output PrintStream.
os - An output PrintStream to send the data to.

StreamGobbler

public StreamGobbler(java.lang.String input,
                     java.io.OutputStream os)
Constructor for the StreamGobbler object that gobbles input instead of the default outputstreams. It sends the data to the passed in output PrintStream.

Parameters:
os - An output PrintStream to send the data to.
Method Detail

run

public void run()
Main processing method for the StreamGobbler object


abort

public void abort()

setOs_

public void setOs_(java.io.PrintStream ps_)
Set Method for class field 'ps_'.

Parameters:
ps_ - is the value to set this class field to.

getOs_

public java.io.PrintStream getOs_()
Get Method for class field 'ps_'.

Returns:
PrintStream - The value the class field 'ps_'.

getCapturedOutput

public java.lang.String getCapturedOutput()
Gets the inputStreams captured data.

Returns:
StringBuffer - The value the class field 'captureBuffer_'.

setCapture

public void setCapture(boolean capture)
Set Method for class field 'capture_'. It turns on or off this classes ability to capture and internally stor the InputStream data.


getCapture

public boolean getCapture()
Get Method for class field 'capture_'.

Returns:
boolean - The value the class field 'capture_'.