Class ProcessConsumer


  • public class ProcessConsumer
    extends java.lang.Object
    A class that allows clients to asynchronously consume the output of a Processs input and error streams. The task is asynchronous to avoid deadlocks when both streams need to be read in order for the process to proceed.
    • Constructor Summary

      Constructors 
      Constructor Description
      ProcessConsumer()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.concurrent.Future<IOResult> consume​(java.io.InputStream is)
      Read the given input stream line-by-line.
      static java.util.concurrent.Future<IOResult> consume​(java.io.InputStream is, java.util.function.Consumer<java.lang.String> lineConsumer)
      Read the given input stream line-by-line.
      • Methods inherited from class java.lang.Object

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

      • ProcessConsumer

        public ProcessConsumer()
    • Method Detail

      • consume

        public static java.util.concurrent.Future<IOResult> consume​(java.io.InputStream is)
        Read the given input stream line-by-line.

        To get all output after all reading is done you can call the blocking operation Future.get().

        Parameters:
        is - the input stream
        Returns:
        the future that will be complete when all lines are read
      • consume

        public static java.util.concurrent.Future<IOResult> consume​(java.io.InputStream is,
                                                                    java.util.function.Consumer<java.lang.String> lineConsumer)
        Read the given input stream line-by-line.

        If you wish to get all output after all reading is done you can call the blocking operation Future.get().

        Parameters:
        is - the input stream
        lineConsumer - the line consumer; may be null
        Returns:
        the future that will be complete when all lines are read