net.groboclown.util.thread.v1
Class IOThreadRunner

java.lang.Object
  |
  +--net.groboclown.util.thread.v1.IOThreadRunner

public class IOThreadRunner
extends Object

Loops, reading from the input stream and writes to the output stream.

See Also:
LoopThread

Field Summary
private  byte[] buffer
           
private static int BUFFER_SIZE
           
private  boolean closeInputOnEOF
           
private  boolean closeOutputOnEOF
           
private  IOException exception
           
private  InputStream is
           
private  LoopThread lt
           
private  Runnable ltRunner
           
private  OutputStream os
           
 
Constructor Summary
IOThreadRunner(InputStream is, OutputStream os)
          Create a new ThreadRunner, re-routing is data into the os stream.
IOThreadRunner(LoopThread lt, InputStream is, OutputStream os)
          Create a new ThreadRunner, re-routing is data into the os stream, but uses the initialization of the given LoopThread.
 
Method Summary
 IOException getException()
          Retrieves the most recent exception that occured, if any.
 OutputStream getOutputStream()
          Retrieves the output stream that the input is redirected to.
 LoopThread getThread()
          Retrieves the LoopThread instance that manages the operation.
 boolean isReading()
           
protected  void reachedEOF()
          Stop the reading and void out any exceptions.
protected  void registerException(IOException ioe)
          Post an exception, and stop the reading.
 void setCloseInputOnStop(boolean on)
          By setting this to true the runner will close the InputStream once a Stop signal has been encountered.
 void setCloseOutputOnStop(boolean on)
          By setting this to true the runner will close the OutputStream once a Stop signal has been encountered.
 void start()
          Starts the stream reading.
 void stop()
          Stops the thread from reading.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

private static final int BUFFER_SIZE

is

private InputStream is

os

private OutputStream os

buffer

private byte[] buffer

lt

private LoopThread lt

exception

private IOException exception

closeInputOnEOF

private boolean closeInputOnEOF

closeOutputOnEOF

private boolean closeOutputOnEOF

ltRunner

private Runnable ltRunner
Constructor Detail

IOThreadRunner

public IOThreadRunner(InputStream is,
                      OutputStream os)
Create a new ThreadRunner, re-routing is data into the os stream.

IOThreadRunner

public IOThreadRunner(LoopThread lt,
                      InputStream is,
                      OutputStream os)
Create a new ThreadRunner, re-routing is data into the os stream, but uses the initialization of the given LoopThread. Note that lt must not be a running thread.
Method Detail

getException

public IOException getException()
Retrieves the most recent exception that occured, if any. If no exception happened, then it returns null.

setCloseInputOnStop

public void setCloseInputOnStop(boolean on)
By setting this to true the runner will close the InputStream once a Stop signal has been encountered.

setCloseOutputOnStop

public void setCloseOutputOnStop(boolean on)
By setting this to true the runner will close the OutputStream once a Stop signal has been encountered.

getThread

public LoopThread getThread()
Retrieves the LoopThread instance that manages the operation. You can use this instance for setting up the thread (such as setting priority and daemon status).

getOutputStream

public OutputStream getOutputStream()
Retrieves the output stream that the input is redirected to.

isReading

public boolean isReading()
Returns:
true if the thread is alive and reading the stream, or false if it is not reading.

start

public void start()
Starts the stream reading.

stop

public void stop()
          throws IOException
Stops the thread from reading.

registerException

protected void registerException(IOException ioe)
Post an exception, and stop the reading.

reachedEOF

protected void reachedEOF()
Stop the reading and void out any exceptions.


Written under the LGPL