1 5 6 package org.exoplatform.portlet.commons.servlet; 7 8 import javax.servlet.http.HttpServletResponseWrapper ; 9 import java.io.ByteArrayOutputStream ; 10 import java.io.IOException ; 11 import java.io.PrintWriter ; 12 import javax.servlet.ServletOutputStream ; 13 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.RenderResponseImp; 14 15 21 22 23 public class BufferedServletResponse extends HttpServletResponseWrapper { 24 25 private RenderOutputStream outStream; 26 27 public BufferedServletResponse(RenderResponseImp renderResponse) { 28 super(renderResponse); 29 outStream = new RenderOutputStream(new ByteArrayOutputStream ()); 30 } 31 32 public void flushBuffer() throws IOException { 33 outStream.flushBuffer(); 34 } 35 36 public void closeBuffer() throws IOException { 37 outStream.closeBuffer(); 38 } 39 40 public PrintWriter getWriter() throws IOException { 41 return new PrintWriter (outStream.baos); 42 } 44 45 public ServletOutputStream getOutputStream() throws IOException { 46 47 return outStream; 48 } 49 50 public byte[] toByteArray() { 51 return outStream.baos.toByteArray(); 52 } 53 54 public void reset() { 55 super.reset(); 56 } 57 58 private class RenderOutputStream extends ServletOutputStream 59 { 60 public ByteArrayOutputStream baos; 61 62 public RenderOutputStream(ByteArrayOutputStream baos) { 63 this.baos = baos; 64 } 65 66 public void write(int i) throws IOException { 67 baos.write(i); 68 } 69 70 public void flush() 71 {} 72 73 public void close() 74 {} 75 76 public void flushBuffer() throws IOException { 77 super.flush(); 78 } 79 80 public void closeBuffer() throws IOException { 81 super.close(); 82 } 83 84 85 } 86 87 } 88 | Popular Tags |