com.perdues
Class CharPump
java.lang.Object
java.lang.Thread
com.perdues.CharPump
- All Implemented Interfaces:
- Runnable
public class CharPump
- extends Thread
Copies from the Reader to the Writer until it reaches the end of the
InputStream or throws an Exception. This class provides "glue" when
you need to supply the data from a Reader to a Writer. Instances can
be configured to close the Writer upon thread termination. Normally
they do not close the Writer, so you can concatenate outputs and use
System.out or System.err for output. If the Reader's underlying
InputStream is interruptible, you can break out of a read and
terminate this thread by interrupting it.
Constructor Summary |
CharPump(Reader in,
Writer out)
Creates a CharPump that will copy the Reader to the Writer until it
reaches the end of the Reader 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 this CharPump's closeOnExit status. |
void |
run()
The thread automatically runs this method. |
void |
setCloseOnExit(boolean request)
Setting closeOnExit causes this to reliably close its Writer
when 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 |
CharPump
public CharPump(Reader in,
Writer out)
- Creates a CharPump that will copy the Reader to the Writer until it
reaches the end of the Reader or throws an Exception. This will
terminate on a thread interrupt if the current I/O operation
responds to the interrupt. You will need to call the
start method to make it go. Marks the new thread as a
daemon so its existence cannot stop the JVM from exiting.
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 its Writer
when the thread terminates. It is initially not set.
isCloseOnExit
public boolean isCloseOnExit()
- Returns this CharPump's 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