KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > servlet > filter > ByteArrayResponseWrapper


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.servlet.filter;
4
5 import java.io.PrintWriter 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  * ByteArray implementation of HttpServletResponseWrapper.
14  */

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

37     public String JavaDoc toString() {
38         return tpStream.getByteArrayStream().toString();
39     }
40
41     /**
42      * Get the underlying character array.
43      */

44     public char[] toCharArray() {
45         return tpStream.getByteArrayStream().toString().toCharArray();
46     }
47
48     /**
49      * Get the underlying byte array.
50      */

51     public byte[] toByteArray() {
52         return tpStream.getByteArrayStream().toByteArray();
53     }
54
55
56     public void reset() {
57         tpStream.reset();
58     }
59 }
60
61
Popular Tags