FileDocCategorySizeDatePackage
SystemLogHandler.javaAPI DocGlassfish v2 API6170Fri May 04 22:32:58 BST 2007org.apache.jasper.util

SystemLogHandler

public class SystemLogHandler extends PrintStream
This helper class may be used to do sophisticated redirection of System.out and System.err.
author
Remy Maucherat

Fields Summary
protected PrintStream
wrapped
Wrapped PrintStream.
protected static final ThreadLocal
streams
Thread <-> PrintStream associations.
protected static final ThreadLocal
data
Thread <-> ByteArrayOutputStream associations.
Constructors Summary
public SystemLogHandler(PrintStream wrapped)
Construct the handler to capture the output of the given steam.

        super(wrapped);
        this.wrapped = wrapped;
    
Methods Summary
public booleancheckError()

        return findStream().checkError();
    
public voidclose()

        findStream().close();
    
protected java.io.PrintStreamfindStream()
Find PrintStream to which the output must be written to.

        PrintStream ps = (PrintStream) streams.get();
        if (ps == null) {
            ps = wrapped;
        }
        return ps;
    
public voidflush()

        findStream().flush();
    
public java.io.PrintStreamgetWrapped()



    // --------------------------------------------------------- Public Methods


       
      return wrapped;
    
public voidprint(boolean b)

        findStream().print(b);
    
public voidprint(char c)

        findStream().print(c);
    
public voidprint(int i)

        findStream().print(i);
    
public voidprint(long l)

        findStream().print(l);
    
public voidprint(float f)

        findStream().print(f);
    
public voidprint(double d)

        findStream().print(d);
    
public voidprint(char[] s)

        findStream().print(s);
    
public voidprint(java.lang.String s)

        findStream().print(s);
    
public voidprint(java.lang.Object obj)

        findStream().print(obj);
    
public voidprintln()

        findStream().println();
    
public voidprintln(boolean x)

        findStream().println(x);
    
public voidprintln(char x)

        findStream().println(x);
    
public voidprintln(int x)

        findStream().println(x);
    
public voidprintln(long x)

        findStream().println(x);
    
public voidprintln(float x)

        findStream().println(x);
    
public voidprintln(double x)

        findStream().println(x);
    
public voidprintln(char[] x)

        findStream().println(x);
    
public voidprintln(java.lang.String x)

        findStream().println(x);
    
public voidprintln(java.lang.Object x)

        findStream().println(x);
    
protected voidsetError()

        //findStream().setError();
    
public static voidsetThread()
Start capturing thread's output.

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        data.set(baos);
        streams.set(new PrintStream(baos));
    
public static java.lang.StringunsetThread()
Stop capturing thread's output and return captured data as a String.

        ByteArrayOutputStream baos = 
            (ByteArrayOutputStream) data.get();
        if (baos == null) {
            return null;
        }
        streams.set(null);
        data.set(null);
        return baos.toString();
    
public voidwrite(int b)

        findStream().write(b);
    
public voidwrite(byte[] b)

        findStream().write(b);
    
public voidwrite(byte[] buf, int off, int len)

        findStream().write(buf, off, len);