Class InputStreamThread

java.lang.Object
java.lang.Thread
org.codelibs.fess.util.InputStreamThread
All Implemented Interfaces:
Runnable

public class InputStreamThread extends Thread
A thread that reads from an input stream line by line and maintains a buffer of recent lines. This class provides functionality to read input stream data asynchronously, optionally process each line with a callback function, and maintain a circular buffer of recent lines for retrieval.
  • Field Details

    • MAX_BUFFER_SIZE

      public static final int MAX_BUFFER_SIZE
      Maximum buffer size constant
      See Also:
  • Constructor Details

    • InputStreamThread

      public InputStreamThread(InputStream is, Charset charset, int bufferSize, Consumer<String> outputCallback)
      Creates a new input stream thread.
      Parameters:
      is - the input stream to read from
      charset - the character encoding to use for reading
      bufferSize - the maximum number of lines to keep in the buffer (0 to disable buffering)
      outputCallback - optional callback function to process each line (can be null)
  • Method Details

    • run

      public void run()
      Runs the thread to continuously read lines from the input stream. Each line is processed by the output callback (if provided) and added to the buffer. The buffer is maintained as a circular buffer with the specified size.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • getOutput

      public String getOutput()
      Returns all buffered lines as a single string, separated by newlines.
      Returns:
      the concatenated output of all buffered lines
    • contains

      public boolean contains(String value)
      Checks if the buffer contains a line that matches the specified value (after trimming).
      Parameters:
      value - the value to search for in the buffered lines
      Returns:
      true if a matching line is found, false otherwise