Class PumpStreamHandler

java.lang.Object
org.zeroturnaround.exec.stream.PumpStreamHandler
All Implemented Interfaces:
ExecuteStreamHandler

public class PumpStreamHandler extends Object implements ExecuteStreamHandler
Copies standard output and error of subprocesses to standard output and error of the parent process. If output or error stream are set to null, any feedback from that stream will be lost.
  • Field Details

    • log

      private static final org.slf4j.Logger log
    • outputThread

      protected Thread outputThread
    • errorThread

      protected Thread errorThread
    • inputThread

      protected Thread inputThread
    • out

      protected final OutputStream out
    • err

      protected final OutputStream err
    • input

      protected final InputStream input
    • inputStreamPumper

      protected InputStreamPumper inputStreamPumper
  • Constructor Details

    • PumpStreamHandler

      public PumpStreamHandler()
      Construct a new PumpStreamHandler.
    • PumpStreamHandler

      public PumpStreamHandler(OutputStream outAndErr)
      Construct a new PumpStreamHandler.
      Parameters:
      outAndErr - the output/error OutputStream.
    • PumpStreamHandler

      public PumpStreamHandler(OutputStream out, OutputStream err)
      Construct a new PumpStreamHandler.
      Parameters:
      out - the output OutputStream.
      err - the error OutputStream.
    • PumpStreamHandler

      public PumpStreamHandler(OutputStream out, OutputStream err, InputStream input)
      Construct a new PumpStreamHandler.
      Parameters:
      out - the output OutputStream.
      err - the error OutputStream.
      input - the input InputStream.
  • Method Details

    • setProcessOutputStream

      public void setProcessOutputStream(InputStream is)
      Set the InputStream from which to read the standard output of the process.
      Specified by:
      setProcessOutputStream in interface ExecuteStreamHandler
      Parameters:
      is - the InputStream.
    • setProcessErrorStream

      public void setProcessErrorStream(InputStream is)
      Set the InputStream from which to read the standard error of the process.
      Specified by:
      setProcessErrorStream in interface ExecuteStreamHandler
      Parameters:
      is - the InputStream.
    • setProcessInputStream

      public void setProcessInputStream(OutputStream os)
      Set the OutputStream by means of which input can be sent to the process.
      Specified by:
      setProcessInputStream in interface ExecuteStreamHandler
      Parameters:
      os - the OutputStream.
    • start

      public void start()
      Start the Threads.
      Specified by:
      start in interface ExecuteStreamHandler
    • stop

      public void stop()
      Stop pumping the streams.
      Specified by:
      stop in interface ExecuteStreamHandler
    • flush

      public void flush()
    • getOut

      public OutputStream getOut()
      Get the output stream.
      Returns:
      OutputStream.
    • getErr

      public OutputStream getErr()
      Get the error stream.
      Returns:
      OutputStream.
    • getInput

      public InputStream getInput()
      Get the input stream.
      Returns:
      InputStream.
    • createProcessOutputPump

      protected void createProcessOutputPump(InputStream is, OutputStream os)
      Create the pump to handle process output.
      Parameters:
      is - the InputStream.
      os - the OutputStream.
    • createProcessErrorPump

      protected void createProcessErrorPump(InputStream is, OutputStream os)
      Create the pump to handle error output.
      Parameters:
      is - the InputStream.
      os - the OutputStream.
    • createPump

      protected Thread createPump(InputStream is, OutputStream os)
      Creates a stream pumper to copy the given input stream to the given output stream.
      Parameters:
      is - the input stream to copy from
      os - the output stream to copy into
      Returns:
      the stream pumper thread
    • createPump

      protected Thread createPump(InputStream is, OutputStream os, boolean closeWhenExhausted)
      Creates a stream pumper to copy the given input stream to the given output stream.
      Parameters:
      is - the input stream to copy from
      os - the output stream to copy into
      closeWhenExhausted - close the output stream when the input stream is exhausted
      Returns:
      the stream pumper thread
    • createPump

      protected Thread createPump(InputStream is, OutputStream os, boolean closeWhenExhausted, boolean flushImmediately)
      Creates a stream pumper to copy the given input stream to the given output stream.
      Parameters:
      is - the input stream to copy from
      os - the output stream to copy into
      closeWhenExhausted - close the output stream when the input stream is exhausted
      flushImmediately - flush the output stream whenever data was written to it
      Returns:
      the stream pumper thread
    • createSystemInPump

      protected Thread createSystemInPump(InputStream is, OutputStream os)
      Creates a stream pumper to copy the given input stream to the given output stream.
      Parameters:
      is - the System.in input stream to copy from
      os - the output stream to copy into
      Returns:
      the stream pumper thread
    • newThread

      protected Thread newThread(Runnable task)
      Override this to customize how the background task is created.
      Parameters:
      task - the task to be run in the background
      Returns:
      the thread of the task
    • wrapTask

      protected Runnable wrapTask(Runnable task)
      Override this to customize how the background task is created.
      Parameters:
      task - the task to be run in the background
      Returns:
      the runnable of the wrapped task