/* * BufferOutputStream.java * * Created on June 2, 2005, 2:45 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.ByteArrayOutputStream; import java.io.IOException; import javax.servlet.ServletOutputStream; /** * * @author LBlaze */ public class BufferOutputStream extends ServletOutputStream { protected ByteArrayOutputStream buffer; /** Creates a new instance of BufferOutputStream */ public BufferOutputStream() { buffer = new ByteArrayOutputStream(); } public void write(int b) throws IOException { buffer.write(b); } public void write(byte b[]) throws IOException { buffer.write(b); } public void write(byte[] b, int off, int len) throws IOException { buffer.write(b, off, len); } public void flush() throws IOException { buffer.flush(); } public void close() throws IOException { buffer.close(); } public byte[] getContentsAsByteArray() throws IOException { flush(); return buffer.toByteArray(); } }