/** * START File FileCaptureResponseWrapper.java */ package com.junjing.filter; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class FileCaptureResponseWrapper extends HttpServletResponseWrapper { private CharArrayWriter output; public String toString() { return output.toString(); } public FileCaptureResponseWrapper(HttpServletResponse response) { super(response); output = new CharArrayWriter(); } public PrintWriter getWriter() { return new PrintWriter(output); } public void writeFile(String fileName) throws IOException { FileWriter fw = new FileWriter(fileName); fw.write( output.toString()); fw.close(); } public ServletOutputStream getOutputStream() throws java.io.IOException { return new ServletOutputStream(); } public void write(int b) throws IOException { output.write(b); } public void write(byte b[]) throws IOException { output.write(new String(b,"GBK")); } public void write(byte b[], int off, int len) throws IOException { output.write(new String(b, off, len)); } }; } public void writeResponse(PrintWriter out) { out.print(output.toCharArray()); } } /** * END File FileCaptureResponseWrapper.java */ |