Class ProcessLoggingThread

java.lang.Object
java.lang.Thread
org.eclipse.mosaic.lib.util.ProcessLoggingThread
All Implemented Interfaces:
Runnable

public class ProcessLoggingThread extends Thread
A thread which reads lines from a provided InputStream (e.g., stdout of a process), and feeds them into a Consumer to print or log the read lines.
  • Constructor Details

  • Method Details

    • teeInputStream

      public InputStream teeInputStream()
      An InputStream cannot be read twice. Reading it simultaneously results in unexpected results and blocking. Therefore, this method creates a copy of the initially provided InputStream which can be read simultaneously by another thread by using a buffer which is filled by reading the initially provided stream.

      Note: If the returned InputStream is not processed/read constantly, lines produced by the initial input stream might be lost, since only a limited number of lines are buffered.
      Returns:
      an InputStream returning the output produced by the initially provided InputStream
    • close

      public void close()
    • run

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