Class StreamForwarder

  • All Implemented Interfaces:
    java.lang.Runnable

    public final class StreamForwarder
    extends java.lang.Thread
    A simple stream forwarder that uses a daemon thread to read from an InputStream and write it to a OutputStream. A small buffer is used (typically 1 KB) to improve performance. Any exceptions will be ignored.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • 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
      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.
      • 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
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 thread
        in - the InputStream to read from.
        out - the OutputStream to write to, or null to 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 - the InputStream to read from.
        out - the OutputStream to 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:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread