TeePrintStream

class TeePrintStream(delegate: PrintStream, lineSink: (String) -> Unit) : PrintStream(source)

PrintStream that mirrors every byte to a wrapped delegate and buffers the bytes into a line-completion buffer. On every newline boundary the buffered text is decoded as UTF-8 and passed to lineSink. A trailing \r (Windows line ending) is stripped before the sink call.

Thread-safe: writes synchronize on an internal lock so concurrent writes from multiple threads cannot interleave bytes inside the line buffer. lineSink is invoked from whichever thread completed the line. The sink is responsible for any further dispatching it needs (e.g. onto a UI thread).

Substrate-level JVM utility — usable by any host that needs to tee a PrintStream line-by-line. Pairs with StdoutCapture for the common System.out / System.err capture case.

Constructors

Link copied to clipboard
constructor(delegate: PrintStream, lineSink: (String) -> Unit)

Functions

Link copied to clipboard
open override fun close()