Package nl.esciencecenter.xenon.utils
Class StreamForwarder
- java.lang.Object
-
- java.lang.Thread
-
- nl.esciencecenter.xenon.utils.StreamForwarder
-
- All Implemented Interfaces:
java.lang.Runnable
public final class StreamForwarder extends java.lang.ThreadA simple stream forwarder that uses a daemon thread to read from anInputStreamand write it to aOutputStream. A small buffer is used (typically 1 KB) to improve performance. Any exceptions will be ignored.
-
-
Constructor Summary
Constructors Constructor Description StreamForwarder(java.io.InputStream in, java.io.OutputStream out)Create a new StreamForwarder and start it immediately.StreamForwarder(java.lang.String name, java.io.InputStream in, java.io.OutputStream out, int bufferSize)Create a new StreamForwarder and start it immediately.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidrun()Main entry method for the daemon thread.voidterminate(long timeout)Wait for a given timeout for the StreamForwarder to terminate by reading an end-of-stream on the input.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Constructor Detail
-
StreamForwarder
public StreamForwarder(java.lang.String name, java.io.InputStream in, java.io.OutputStream out, int bufferSize)Create a new StreamForwarder and start it immediately.- Parameters:
name- the name of the threadin- theInputStreamto read from.out- theOutputStreamto write to, ornullto discard the output.bufferSize- the buffer size to use, or 0 to use the default.
-
StreamForwarder
public StreamForwarder(java.io.InputStream in, java.io.OutputStream out)Create a new StreamForwarder and start it immediately.- Parameters:
in- theInputStreamto read from.out- theOutputStreamto write to.
-
-
Method Detail
-
terminate
public void terminate(long timeout)
Wait for a given timeout for the StreamForwarder to terminate by reading an end-of-stream on the input. When the timeout expires both input and output streams will be closed, regardless of whether the input has reached end-of-line.- Parameters:
timeout- The number of milliseconds to wait for termination.
-
run
public void run()
Main entry method for the daemon thread.- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread
-
-