Package groovy.console.ui
Class SystemOutputInterceptor
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
groovy.console.ui.SystemOutputInterceptor
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
Intercepts System.out/System.err. Implementation helper for Console.groovy.
-
Field Summary
Fields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionSystemOutputInterceptor(Closure callback) ConstructorSystemOutputInterceptor(Closure callback, boolean output) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidThreads executing a script should call this method after execution completes in order to unregister the consoleId.voidsetConsoleId(int consoleId) Threads executing a script should call this method at the start of execution in order to set the id of the console that is hosting the thread of execution.voidstart()Starts intercepting System.out/System.errvoidstop()Stops intercepting System.out/System.err, sending output to wherever it was going when this interceptor was created.voidwrite(byte[] b, int off, int len) Intercepts output - more common case of byte[]voidwrite(int b) Intercepts output - single charactersMethods inherited from class java.io.FilterOutputStream
close, flush, writeMethods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
SystemOutputInterceptor
Constructor- Parameters:
callback- accepts the id of the target Console instance and a string to be sent to std out and returns a Boolean. If the return value is true, output will be sent to System.out, otherwise it will not.
-
SystemOutputInterceptor
Constructor- Parameters:
callback- accepts the id of the target Console instance and a string to be sent to std out and returns a Boolean. If the return value is true, output will be sent to System.out/System.err, otherwise it will not.output- flag that tells whether System.out needs capturing ot System.err
-
-
Method Details
-
start
public void start()Starts intercepting System.out/System.err -
stop
public void stop()Stops intercepting System.out/System.err, sending output to wherever it was going when this interceptor was created. -
write
Intercepts output - more common case of byte[]- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
write
Intercepts output - single characters- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
setConsoleId
public void setConsoleId(int consoleId) Threads executing a script should call this method at the start of execution in order to set the id of the console that is hosting the thread of execution. This should be called prior to any output that is generated. The consoleId will be passed to the callback.- Parameters:
consoleId- id of the Console instance executing the script
-
removeConsoleId
public void removeConsoleId()Threads executing a script should call this method after execution completes in order to unregister the consoleId.
-