Package org.codelibs.fess.util
Class InputStreamThread
java.lang.Object
java.lang.Thread
org.codelibs.fess.util.InputStreamThread
- All Implemented Interfaces:
Runnable
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionInputStreamThread(InputStream is, Charset charset, int bufferSize, Consumer<String> outputCallback) Creates a new input stream thread. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if the buffer contains a line that matches the specified value (after trimming).Returns all buffered lines as a single string, separated by newlines.voidrun()Runs the thread to continuously read lines from the input stream.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
MAX_BUFFER_SIZE
public static final int MAX_BUFFER_SIZEMaximum 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 fromcharset- the character encoding to use for readingbufferSize- 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. -
getOutput
Returns all buffered lines as a single string, separated by newlines.- Returns:
- the concatenated output of all buffered lines
-
contains
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
-