// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
package test;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

import javax.servlet.jsp.JspWriter;

public class MyJspWriter extends JspWriter {
    private StringWriter sw;
    private PrintWriter pw;
    private JspWriter original;
    public MyJspWriter(JspWriter original) {
        super(original.getBufferSize(), original.isAutoFlush());
        sw = new StringWriter(); 
        pw = new PrintWriter(sw);
        this.original = original;
    }

    public void newLine() throws IOException {
        original.newLine();
        pw.println();
    }
    public void print(boolean arg0) throws IOException {
        original.print(arg0);
        pw.print(arg0);
    }
    public void print(char arg0) throws IOException {
        original.print(arg0);
        pw.print(arg0);
    }
    public void print(int arg0) throws IOException {
        original.print(arg0);
        pw.print(arg0);
    }
    public void print(long arg0) throws IOException {
        original.print(arg0);
        pw.print(arg0);
    }
    public void print(float arg0) throws IOException {
        original.print(arg0);
        pw.print(arg0);
    }
    public void print(double arg0) throws IOException {
        original.print(arg0);
        pw.print(arg0);
    }
    public void print(char[] arg0) throws IOException {
        original.print(arg0);
        pw.print(arg0);
    }
    public void print(String arg0) throws IOException {
        original.print(arg0);
        pw.print(arg0);
    }
    public void print(Object arg0) throws IOException {
        original.print(arg0);
        pw.print(arg0);
    }
    public void println() throws IOException {
        original.println();
        pw.println();
    }
    public void println(boolean arg0) throws IOException {
        original.println(arg0);
        pw.println(arg0);
    }
    public void println(char arg0) throws IOException {
        original.println(arg0);
        pw.println(arg0);
    }
    public void println(int arg0) throws IOException {
        original.println(arg0);
        pw.println(arg0);
    }
    public void println(long arg0) throws IOException {
        original.println(arg0);
        pw.println(arg0);
    }
    public void println(float arg0) throws IOException {
        original.println(arg0);
        pw.println(arg0);
    }
    public void println(double arg0) throws IOException {
        original.println(arg0);
        pw.println(arg0);
    }
    public void println(char[] arg0) throws IOException {
        original.println(arg0);
        pw.println(arg0);
    }
    public void println(String arg0) throws IOException {
        original.println(arg0);
        pw.println(arg0);
    }
    public void println(Object arg0) throws IOException {
        original.println(arg0);
        pw.println(arg0);
    }
    public void clear() throws IOException {
        original.clear();
        sw = new StringWriter(); 
        pw = new PrintWriter(sw);
    }
    public void clearBuffer() throws IOException {
        original.clear();
        sw = new StringWriter(); 
        pw = new PrintWriter(sw);
    }
    public void flush() throws IOException {
        original.flush();
        pw.flush();
        sw.flush();
    }
    public void close() throws IOException {
        original.close();
        pw.close();
        sw.close();
    }
    public int getRemaining() {
        return original.getRemaining();
    }
    public void write(char[] cbuf, int off, int len) throws IOException {
        original.write(cbuf,off, len);
        sw.write(cbuf, off,len);
    }
    
    public String getContent() {
        pw.flush();
        sw.flush();
        return sw.getBuffer().toString();
    }
}
