Class ThreadLocalPrintStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.io.PrintStream
org.ek9lang.compiler.backend.jvm.ThreadLocalPrintStream
- All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable
A PrintStream that delegates to thread-local outputs.
This enables parallel execution where each thread captures
its own output without interference from other threads.
When a thread has registered an output stream (via setThreadOutput(ByteArrayOutputStream)),
all writes from that thread go to its specific stream. Otherwise, writes go
to the fallback stream (typically the original System.out).
This class is thread-safe. Each thread's output is completely isolated.
Used by REPL and bytecode tests to capture program output.
-
Field Summary
Fields inherited from class FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionThreadLocalPrintStream(PrintStream fallback) Create a thread-local delegating PrintStream. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringClear the thread-local output and return the captured content.Get the fallback stream (original System.out).static voidsetThreadOutput(ByteArrayOutputStream output) Set the output capture for the current thread.Methods inherited from class PrintStream
append, append, append, charset, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write, write, writeBytesMethods inherited from class OutputStream
nullOutputStream
-
Constructor Details
-
ThreadLocalPrintStream
Create a thread-local delegating PrintStream.- Parameters:
fallback- The stream to use when no thread-local output is registered
-
-
Method Details
-
setThreadOutput
Set the output capture for the current thread. All subsequent writes from this thread will go to this stream.- Parameters:
output- The stream to capture output to
-
clearAndGet
Clear the thread-local output and return the captured content.- Returns:
- The captured output, or empty string if nothing was captured
-
getFallback
Get the fallback stream (original System.out).
-