KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > filters > ByteArrayResponseWrapper


1 package org.roller.presentation.filters;
2
3 import java.io.PrintWriter JavaDoc;
4 import java.io.OutputStreamWriter JavaDoc;
5 import java.io.ByteArrayOutputStream JavaDoc;
6
7 import javax.servlet.ServletOutputStream JavaDoc;
8 import javax.servlet.ServletResponse JavaDoc;
9 import javax.servlet.http.HttpServletResponse JavaDoc;
10 import javax.servlet.http.HttpServletResponseWrapper JavaDoc;
11
12 /*
13  * @author llavandowska
14  *
15  * Implementation of HttpServletResponseWrapper.
16  */

17 public class ByteArrayResponseWrapper extends HttpServletResponseWrapper JavaDoc
18 {
19     private PrintWriter JavaDoc tpWriter;
20     private ByteArrayOutputStreamWrapper tpStream;
21
22     public ByteArrayResponseWrapper(ServletResponse JavaDoc inResp)
23     throws java.io.IOException JavaDoc
24     {
25         super((HttpServletResponse JavaDoc) inResp);
26         tpStream = new ByteArrayOutputStreamWrapper(inResp.getOutputStream());
27         tpWriter = new PrintWriter JavaDoc(new OutputStreamWriter JavaDoc(tpStream,"UTF-8"));
28     }
29
30     public ServletOutputStream JavaDoc getOutputStream()
31     throws java.io.IOException JavaDoc
32     {
33         return tpStream;
34     }
35
36     public PrintWriter JavaDoc getWriter() throws java.io.IOException JavaDoc
37     {
38         return tpWriter;
39     }
40      
41     /** Get a String representation of the entire buffer.
42      */

43     public String JavaDoc toString()
44     {
45         return tpStream.getByteArrayStream().toString();
46     }
47     
48     public ByteArrayOutputStream JavaDoc getByteArrayOutputStream()
49     throws java.io.IOException JavaDoc
50     {
51         return tpStream.getByteArrayStream();
52     }
53 }
54
Popular Tags