public final class StreamForwarder
extends java.lang.Thread
InputStream
and write it to a
OutputStream
.
A small buffer is used (typically 1 KB) to improve performance. Any exceptions will be ignored.Modifier and Type | Field and Description |
---|---|
private static int |
BUFFER_SIZE |
private boolean |
done |
private java.io.InputStream |
in |
private static org.slf4j.Logger |
LOGGER |
private java.io.OutputStream |
out |
Constructor and Description |
---|
StreamForwarder(java.io.InputStream in,
java.io.OutputStream out)
Create a new StreamForwarder and start it immediately.
|
Modifier and Type | Method and Description |
---|---|
private void |
close(java.io.Closeable c,
java.lang.String error)
Closes the input stream, thereby stopping the stream forwarder, and closing the output stream.
|
private void |
done()
Tell the daemon thread that we are done.
|
void |
run()
Main entry method for the daemon thread.
|
void |
terminate(long timeout)
Wait for a given timeout for the StreamForwarder to terminate by reading an end-of-stream on the input.
|
activeCount, checkAccess, clone, 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
private static final org.slf4j.Logger LOGGER
private static final int BUFFER_SIZE
private final java.io.InputStream in
private final java.io.OutputStream out
private boolean done
public StreamForwarder(java.io.InputStream in, java.io.OutputStream out)
in
- the InputStream
to read from.out
- the OutputStream
to write to.private void close(java.io.Closeable c, java.lang.String error)
c
- The Closeable
to close (i.e., the InputStream
or OutputStream
)error
- The error message to print if the close results in an Exceptionprivate void done()
public void terminate(long timeout)
timeout
- The number of milliseconds to wait for termination.public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread