com.perdues
Class BytePump

java.lang.Object
  extended by java.lang.Thread
      extended by com.perdues.BytePump
All Implemented Interfaces:
Runnable

public class BytePump
extends Thread

A BytePump copies from an InputStream to an OutputStream until end of file or until an Exception or other Throwable occurs. This provides "glue" to supply data from an InputStream to an OutputStream. Instances can be configured to close the OutputStream upon thread termination. Normally they do not close, so you can concatenate outputs and use System.out or System.err for output. For some kinds of underlying InputStreams it is possible to unblock a read operation and terminate this thread with an interrupt. Some InputStreams however can block indefinitely even if interrupted.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
BytePump(InputStream in, OutputStream out)
          Creates a BytePump that will copy from the InputStream to the OutputStream until it reaches the end of the InputStream or throws an Exception.
 
Method Summary
 Throwable getExitCause()
          If this thread terminated because of a Throwable, it makes the value available through this method.
 boolean isCloseOnExit()
          Returns the closeOnExit status.
 void run()
          The thread automatically runs this method.
 void setCloseOnExit(boolean request)
          Setting closeOnExit causes this to reliably close the OutputStream whenever the thread terminates.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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
 

Constructor Detail

BytePump

public BytePump(InputStream in,
                OutputStream out)
Creates a BytePump that will copy from the InputStream to the OutputStream until it reaches the end of the InputStream or throws an Exception. If the I/O operations unblock on a thread interrupt, this will terminate on a thread interrupt. Marks the thread as a Daemon so its existence cannot stop the JVM from exiting. You will need to call the start method to make it go.

Method Detail

getExitCause

public Throwable getExitCause()
If this thread terminated because of a Throwable, it makes the value available through this method.


setCloseOnExit

public void setCloseOnExit(boolean request)
Setting closeOnExit causes this to reliably close the OutputStream whenever the thread terminates. It is initially off.


isCloseOnExit

public boolean isCloseOnExit()
Returns the closeOnExit status.


run

public void run()
The thread automatically runs this method. As usual for subclasses of Thread, this is not intended to be invoked directly by client code, use start instead.

Specified by:
run in interface Runnable
Overrides:
run in class Thread