Package: groovy.console.ui

## [Java] Class SystemOutputInterceptor

- groovy.console.ui.SystemOutputInterceptor

-     public class SystemOutputInterceptor
      extends FilterOutputStream

  Intercepts System.out/System.err. Implementation helper for Console.groovy.

- - ### Constructor Summary

    Constructors
    Constructor and description
    `SystemOutputInterceptor(Closure callback)` Constructor
    `SystemOutputInterceptor(Closure callback, boolean output)` Constructor

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `removeConsoleId()` Threads executing a script should call this method after execution completes in order to unregister the consoleId.
    `` | `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.
    `` | `public void` | `start()` Starts intercepting System.out/System.err
    `` | `public void` | `stop()` Stops intercepting System.out/System.err, sending output to wherever it was going when this interceptor was created.
    `` | `public void` | `write(byte[] b, int off, int len)` Intercepts output - more common case of byte[]
    `` | `public void` | `write(int b)` Intercepts output - single characters

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class FilterOutputStream` | `close, equals, flush, getClass, hashCode, notify, notifyAll, nullOutputStream, toString, wait, wait, wait, write, write, write`

- - ### Constructor Detail

    - #### public SystemOutputInterceptor(Closure callback)

      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.

    - #### public SystemOutputInterceptor(Closure callback, boolean output)

      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 Detail

    - #### public void removeConsoleId()

      Threads executing a script should call this method after execution completes in order to unregister the consoleId.

    - #### 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

    - #### public void start()

      Starts intercepting System.out/System.err

    - #### public void stop()

      Stops intercepting System.out/System.err, sending output to wherever it was going when this interceptor was created.

    - #### public void write(byte[] b, int off, int len)

      Intercepts output - more common case of byte[]

    - #### public void write(int b)

      Intercepts output - single characters