Class StreamConsumer

java.lang.Object
org.opencastproject.util.StreamConsumer
All Implemented Interfaces:
Runnable

public class StreamConsumer extends Object implements Runnable
A StreamConsumer helps to asynchronously consume a text input stream line by line. The consumer guarantees the closing of the stream.
  • Constructor Details

    • StreamConsumer

      public StreamConsumer(com.entwinemedia.fn.Fn<String,Boolean> consumer)
      Create a new stream consumer.
      Parameters:
      consumer - a predicate function that may stop reading further lines by returning false
  • Method Details

    • run

      public void run()
      Specified by:
      run in interface Runnable
    • waitUntilRunning

      public void waitUntilRunning()
      Wait for the executing thread to run.
    • waitUntilFinished

      public void waitUntilFinished()
      Wait until the stream has been fully consumed.
    • stopConsuming

      public void stopConsuming()
      Forcibly stop consuming the stream.
    • consume

      public void consume(InputStream stream)
      Start consuming stream. It is guaranteed that the stream gets closed.