Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright 2003-2007 the original author or authors.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package groovy.ui;
Intercepts System.out. Implementation helper for Console.groovy.

$Id: 7797 2007-08-28 15:36:50Z shemnon $
public class SystemOutputInterceptor extends FilterOutputStream {
    private Closure callback;


callback accepts 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(final Closure callback) {
        assert callback != null;
        this. = callback;

Starts intercepting System.out
    public void start() {
        System.setOut(new PrintStream(this));

Stops intercepting System.out, sending output to whereever it was going when this interceptor was created.
    public void stop() {

Intercepts output - moret common case of byte[]
    public void write(byte[] bint offint lenthrows IOException {
        Boolean result = ( String(bofflen));
        if (result.booleanValue()) {

Intercepts output - single characters
    public void write(int bthrows IOException {
        Boolean result = (;
        if (result.booleanValue()) {
New to GrepCode? Check out our FAQ X