gate.util
Class ProcessManager.StreamGobbler

java.lang.Object
  extended by gate.util.ProcessManager.StreamGobbler
All Implemented Interfaces:
Runnable
Enclosing class:
ProcessManager

private class ProcessManager.StreamGobbler
extends Object
implements Runnable

Thread body that takes a stream and either consumes it silently or echoes it to another stream.


Field Summary
private  byte[] buf
          Buffer used for reading and writing.
private  boolean done
          Are we finished?
private  Exception exception
          If an exception is thrown during gobbling, it is stored here.
private  InputStream inputStream
          The input stream to gobble.
private  OutputStream outputStream
          The output stream to echo to.
 
Constructor Summary
private ProcessManager.StreamGobbler()
           
 
Method Summary
(package private)  Exception getException()
          Return the last exception thrown.
(package private)  boolean hasException()
          Has an exception been thrown since getException() was last called?
(package private)  boolean isDone()
           
(package private)  void reset()
          Reset state.
 void run()
          Main body of the thread.
(package private)  void setInputStream(InputStream is)
          Set the stream to gobble.
(package private)  void setOutputStream(OutputStream os)
          Set the output stream to redirect output to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputStream

private InputStream inputStream
The input stream to gobble. If this is null, the thread is idle.


outputStream

private OutputStream outputStream
The output stream to echo to. If this is null the gobbler silently discards the input stream contents.


buf

private byte[] buf
Buffer used for reading and writing.


done

private boolean done
Are we finished? This is set to true once the stream has been emptied.


exception

private Exception exception
If an exception is thrown during gobbling, it is stored here.

Constructor Detail

ProcessManager.StreamGobbler

private ProcessManager.StreamGobbler()
Method Detail

setInputStream

void setInputStream(InputStream is)
Set the stream to gobble. This should not be called while the thread is active.


setOutputStream

void setOutputStream(OutputStream os)
Set the output stream to redirect output to. A value of null indicates that we should discard the output without echoing it.


hasException

boolean hasException()
Has an exception been thrown since getException() was last called?


getException

Exception getException()
Return the last exception thrown. This also resets the cached exception to null.


isDone

boolean isDone()

reset

void reset()
Reset state.


run

public void run()
Main body of the thread. Waits until we have been given a stream to gobble, then reads it until there is no more input available.

Specified by:
run in interface Runnable