Class DefaultConsoleOutputInterceptor
- java.lang.Object
-
- de.gebit.integrity.runner.console.intercept.DefaultConsoleOutputInterceptor
-
- All Implemented Interfaces:
ConsoleOutputInterceptor
public class DefaultConsoleOutputInterceptor extends Object implements ConsoleOutputInterceptor
Default implementation of a console output interceptor. Hooks the System.out and System.err streams to do its work, thus it is critical that there's only one instance of this service in a given JVM. This imlementation automatically hooks the streams when at least one target is registered, and unhooks them when the last target unregisters.- Author:
- Rene Schneider - initial API and implementation
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classDefaultConsoleOutputInterceptor.InterceptPrintStreamThis stream is the core of this service: it captures all data being printed through it, splits it into single lines and forwards the lines to all targets.
-
Field Summary
Fields Modifier and Type Field Description protected DefaultConsoleOutputInterceptor.InterceptPrintStreaminterceptStderrThe interceptor stream for STDERR.protected DefaultConsoleOutputInterceptor.InterceptPrintStreaminterceptStdoutThe interceptor stream for STDOUT.protected PrintStreamstderrThe original STDERR stream.protected PrintStreamstdoutThe original STDOUT stream.protected List<ConsoleInterceptorTarget>targetsThe interception targets.protected ObjecttargetSyncA sync object used to synchronize interception target access.
-
Constructor Summary
Constructors Constructor Description DefaultConsoleOutputInterceptor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidprintlnStdErr(String aLine)Prints a line on the original System.err stream, including an added newline.voidprintlnStdOut(String aLine)Prints a line on the original System.out stream, including an added newline.voidprintStdErr(String aText)Prints text on the original System.err stream.voidprintStdOut(String aText)Prints text on the original System.out stream.voidregisterTarget(ConsoleInterceptorTarget aTarget)Registers a target for intercepted data.voidunregisterTarget(ConsoleInterceptorTarget aTarget)Unregisters a registered target.protected voidupdateStreamCapture()Reevaluates whether the streams are to be captured at the time of calling, and hooks or unhooks the streams as necessary.
-
-
-
Field Detail
-
targetSync
protected final Object targetSync
A sync object used to synchronize interception target access.
-
targets
protected List<ConsoleInterceptorTarget> targets
The interception targets.
-
stdout
protected final PrintStream stdout
The original STDOUT stream.
-
interceptStdout
protected DefaultConsoleOutputInterceptor.InterceptPrintStream interceptStdout
The interceptor stream for STDOUT.
-
stderr
protected final PrintStream stderr
The original STDERR stream.
-
interceptStderr
protected DefaultConsoleOutputInterceptor.InterceptPrintStream interceptStderr
The interceptor stream for STDERR.
-
-
Method Detail
-
updateStreamCapture
protected void updateStreamCapture()
Reevaluates whether the streams are to be captured at the time of calling, and hooks or unhooks the streams as necessary.
-
registerTarget
public void registerTarget(ConsoleInterceptorTarget aTarget)
Description copied from interface:ConsoleOutputInterceptorRegisters a target for intercepted data.- Specified by:
registerTargetin interfaceConsoleOutputInterceptor- Parameters:
aTarget- the target to register
-
unregisterTarget
public void unregisterTarget(ConsoleInterceptorTarget aTarget)
Description copied from interface:ConsoleOutputInterceptorUnregisters a registered target.- Specified by:
unregisterTargetin interfaceConsoleOutputInterceptor- Parameters:
aTarget- the target to unregister
-
printlnStdErr
public void printlnStdErr(String aLine)
Description copied from interface:ConsoleOutputInterceptorPrints a line on the original System.err stream, including an added newline. Automatically flushes the stream.- Specified by:
printlnStdErrin interfaceConsoleOutputInterceptor- Parameters:
aLine- the line- See Also:
PrintWriter.println(String)
-
printStdErr
public void printStdErr(String aText)
Description copied from interface:ConsoleOutputInterceptorPrints text on the original System.err stream.- Specified by:
printStdErrin interfaceConsoleOutputInterceptor- Parameters:
aText- the text to print- See Also:
PrintWriter.print(String)
-
printlnStdOut
public void printlnStdOut(String aLine)
Description copied from interface:ConsoleOutputInterceptorPrints a line on the original System.out stream, including an added newline. Automatically flushes the stream.- Specified by:
printlnStdOutin interfaceConsoleOutputInterceptor- Parameters:
aLine- the line- See Also:
PrintWriter.println(String)
-
printStdOut
public void printStdOut(String aText)
Description copied from interface:ConsoleOutputInterceptorPrints text on the original System.out stream.- Specified by:
printStdOutin interfaceConsoleOutputInterceptor- Parameters:
aText- the text to print- See Also:
PrintWriter.print(String)
-
-