/* * BufferedResponse.java * * Created on June 2, 2005, 2:15 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package com.xpn.xwiki.web.includeservletasstring; import java.io.IOException; import java.io.PrintWriter; import java.io.OutputStreamWriter; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; /** * * @author LBlaze */ public class BufferedResponse extends HttpServletResponseWrapper { protected HttpServletResponse internalResponse; protected BufferOutputStream outputStream; protected PrintWriter writer; /** Creates a new instance of BufferedResponse */ public BufferedResponse(HttpServletResponse internalResponse) { super(internalResponse); this.internalResponse = internalResponse; } public ServletOutputStream getOutputStream() throws IOException { if( outputStream == null ) { outputStream = new BufferOutputStream(); } return outputStream; } public PrintWriter getWriter() throws IOException { if( writer == null ) { writer = new PrintWriter(new OutputStreamWriter(getOutputStream(), getCharacterEncoding())); } return writer; } public byte[] getBufferAsByteArray() throws IOException { if( writer != null ) { writer.flush(); } outputStream.flush(); return outputStream.getContentsAsByteArray(); } }