KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlet > commons > servlet > BufferedServletResponse


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5
6 package org.exoplatform.portlet.commons.servlet;
7
8 import javax.servlet.http.HttpServletResponseWrapper JavaDoc;
9 import java.io.ByteArrayOutputStream JavaDoc;
10 import java.io.IOException JavaDoc;
11 import java.io.PrintWriter JavaDoc;
12 import javax.servlet.ServletOutputStream JavaDoc;
13 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.RenderResponseImp;
14
15 /**
16  * Created by The eXo Platform SARL .
17  *
18  * @author <a HREF="mailto:geaz@users.sourceforge.net">Gennady Azarenkov</a>
19  * @version $Id: BufferedServletResponse.java 567 2005-01-25 12:51:30Z kravchuk $
20  */

21
22
23 public class BufferedServletResponse extends HttpServletResponseWrapper JavaDoc {
24
25     private RenderOutputStream outStream;
26
27     public BufferedServletResponse(RenderResponseImp renderResponse) {
28         super(renderResponse);
29         outStream = new RenderOutputStream(new ByteArrayOutputStream JavaDoc());
30     }
31
32     public void flushBuffer() throws IOException JavaDoc {
33         outStream.flushBuffer();
34     }
35
36     public void closeBuffer() throws IOException JavaDoc {
37         outStream.closeBuffer();
38     }
39
40     public PrintWriter JavaDoc getWriter() throws IOException JavaDoc {
41         return new PrintWriter JavaDoc(outStream.baos);
42 // return super.getWriter();
43
}
44
45     public ServletOutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
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 JavaDoc
59     {
60         public ByteArrayOutputStream JavaDoc baos;
61
62         public RenderOutputStream(ByteArrayOutputStream JavaDoc baos) {
63             this.baos = baos;
64         }
65
66         public void write(int i) throws IOException JavaDoc {
67             baos.write(i);
68         }
69
70         public void flush()
71         {}
72
73         public void close()
74         {}
75
76         public void flushBuffer() throws IOException JavaDoc {
77            super.flush();
78         }
79
80         public void closeBuffer() throws IOException JavaDoc {
81            super.close();
82         }
83
84
85     }
86
87 }
88
Popular Tags