Class OutputCollector

  • All Implemented Interfaces:
    java.lang.Runnable
    Direct Known Subclasses:
    PerlOutputCollector

    public class OutputCollector
    extends java.lang.Object
    implements java.lang.Runnable
    A class that eats the stdout or stderr of a running Process to prevent deadlock.
    Version:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.InputStream in  
      private java.lang.StringBuilder sb  
    • Constructor Summary

      Constructors 
      Constructor Description
      OutputCollector​(java.io.InputStream in)
      Constructor.
      OutputCollector​(java.io.InputStream in, boolean collect)
      Constructor.
      OutputCollector​(java.io.InputStream in, java.lang.StringBuilder sb)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.StringBuilder getOutput()
      Returns the output collected from the stream.
      protected void handleLineRead​(java.lang.String line)
      Called every time a line is read from the stream.
      void run()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • in

        private java.io.InputStream in
      • sb

        private java.lang.StringBuilder sb
    • Constructor Detail

      • OutputCollector

        public OutputCollector​(java.io.InputStream in)
        Constructor.
        Parameters:
        in - The input stream.
      • OutputCollector

        public OutputCollector​(java.io.InputStream in,
                               java.lang.StringBuilder sb)
        Constructor.
        Parameters:
        in - The input stream.
        sb - The buffer in which to collect the output.
      • OutputCollector

        public OutputCollector​(java.io.InputStream in,
                               boolean collect)
        Constructor.
        Parameters:
        in - The input stream.
        collect - Whether to actually collect the output in a buffer. If this is false, then getOutput() will return null. This parameter can be used if you want to eat, but ignore, stdout or stderr for a process.
    • Method Detail

      • getOutput

        public java.lang.StringBuilder getOutput()
        Returns the output collected from the stream.
        Returns:
        The output.
      • handleLineRead

        protected void handleLineRead​(java.lang.String line)
        Called every time a line is read from the stream. This allows subclasses to handle lines differently. They can also call into the super implementation if they want to log the lines into the buffer.
        Parameters:
        line - The line read.
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable