Class StreamGobbler

java.lang.Object
java.lang.Thread
de.iip_ecosphere.platform.support.plugins.StreamGobbler
All Implemented Interfaces:
Runnable

public class StreamGobbler extends Thread
Simple process stream gobbler.
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • StreamGobbler

      public StreamGobbler(InputStream in, PrintStream out)
      Creates a stream gobbler.
      Parameters:
      in - the process stream
      out - the output stream where to write the process output to
  • Method Details

    • addConsumer

      public StreamGobbler addConsumer(Consumer<String> consumer)
      Adds a line consumer.
      Parameters:
      consumer - the line consumer, may be null for none
      Returns:
      this for chaining
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • attach

      public static void attach(Process process)
      Attaches two default stream gobblers to the given process.
      Parameters:
      process - the process to attach to
    • attach

      public static void attach(Process process, Consumer<String> outConsumer, Consumer<String> errConsumer)
      Attaches two default stream gobblers to the given process with given consumers.
      Parameters:
      process - the process to attach to
      outConsumer - the output stream consumer, may be null for none
      errConsumer - the error stream consumer, may be null for none
    • attach

      public static void attach(Process process, PrintStream out, Consumer<String> outConsumer, PrintStream err, Consumer<String> errConsumer)
      Attaches two stream gobblers to the given process with given consumers.
      Parameters:
      process - the process to attach to
      out - the stream where the process output shall be written to
      outConsumer - the output stream consumer, may be null for none
      err - the stream where the process errors shall be written to
      errConsumer - the error stream consumer, may be null for none