Package de.gebit.integrity.runner.console.intercept

## 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 class` | `DefaultConsoleOutputInterceptor.InterceptPrintStream` | This 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.InterceptPrintStream` | `interceptStderr` | The interceptor stream for STDERR.
    `protected DefaultConsoleOutputInterceptor.InterceptPrintStream` | `interceptStdout` | The interceptor stream for STDOUT.
    `protected PrintStream` | `stderr` | The original STDERR stream.
    `protected PrintStream` | `stdout` | The original STDOUT stream.
    `protected List<ConsoleInterceptorTarget>` | `targets` | The interception targets.
    `protected Object` | `targetSync` | A 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
    --- | --- | ---
    `void` | `printlnStdErr​(String aLine)` | Prints a line on the original System.err stream, including an added newline.
    `void` | `printlnStdOut​(String aLine)` | Prints a line on the original System.out stream, including an added newline.
    `void` | `printStdErr​(String aText)` | Prints text on the original System.err stream.
    `void` | `printStdOut​(String aText)` | Prints text on the original System.out stream.
    `void` | `registerTarget​(ConsoleInterceptorTarget aTarget)` | Registers a target for intercepted data.
    `void` | `unregisterTarget​(ConsoleInterceptorTarget aTarget)` | Unregisters a registered target.
    `protected void` | `updateStreamCapture()` | Reevaluates whether the streams are to be captured at the time of calling, and hooks or unhooks the streams as necessary.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

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

  - ### Constructor Detail

    - #### DefaultConsoleOutputInterceptor

          public DefaultConsoleOutputInterceptor()

  - ### 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: `ConsoleOutputInterceptor`
      Registers a target for intercepted data.
      Specified by:
        `registerTarget` in interface `ConsoleOutputInterceptor`
      Parameters:
        `aTarget` - the target to register

    - #### unregisterTarget

          public void unregisterTarget​(ConsoleInterceptorTarget aTarget)

      Description copied from interface: `ConsoleOutputInterceptor`
      Unregisters a registered target.
      Specified by:
        `unregisterTarget` in interface `ConsoleOutputInterceptor`
      Parameters:
        `aTarget` - the target to unregister

    - #### printlnStdErr

          public void printlnStdErr​(String aLine)

      Description copied from interface: `ConsoleOutputInterceptor`
      Prints a line on the original System.err stream, including an added newline. Automatically flushes the stream.
      Specified by:
        `printlnStdErr` in interface `ConsoleOutputInterceptor`
      Parameters:
        `aLine` - the line
      See Also:
        `PrintWriter.println(String)`

    - #### printStdErr

          public void printStdErr​(String aText)

      Description copied from interface: `ConsoleOutputInterceptor`
      Prints text on the original System.err stream.
      Specified by:
        `printStdErr` in interface `ConsoleOutputInterceptor`
      Parameters:
        `aText` - the text to print
      See Also:
        `PrintWriter.print(String)`

    - #### printlnStdOut

          public void printlnStdOut​(String aLine)

      Description copied from interface: `ConsoleOutputInterceptor`
      Prints a line on the original System.out stream, including an added newline. Automatically flushes the stream.
      Specified by:
        `printlnStdOut` in interface `ConsoleOutputInterceptor`
      Parameters:
        `aLine` - the line
      See Also:
        `PrintWriter.println(String)`

    - #### printStdOut

          public void printStdOut​(String aText)

      Description copied from interface: `ConsoleOutputInterceptor`
      Prints text on the original System.out stream.
      Specified by:
        `printStdOut` in interface `ConsoleOutputInterceptor`
      Parameters:
        `aText` - the text to print
      See Also:
        `PrintWriter.print(String)`