KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > core > util > ByteArrayResponseWrapper


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 package org.apache.roller.ui.core.util;
19
20 import java.io.ByteArrayOutputStream JavaDoc;
21 import java.io.OutputStreamWriter JavaDoc;
22 import java.io.PrintWriter JavaDoc;
23
24 import javax.servlet.ServletOutputStream JavaDoc;
25 import javax.servlet.ServletResponse JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27 import javax.servlet.http.HttpServletResponseWrapper JavaDoc;
28
29 /*
30  * @author llavandowska
31  *
32  * Implementation of HttpServletResponseWrapper.
33  */

34 public class ByteArrayResponseWrapper extends HttpServletResponseWrapper JavaDoc
35 {
36     private PrintWriter JavaDoc tpWriter;
37     private ByteArrayOutputStreamWrapper tpStream;
38
39     public ByteArrayResponseWrapper(ServletResponse JavaDoc inResp)
40     throws java.io.IOException JavaDoc
41     {
42         super((HttpServletResponse JavaDoc) inResp);
43         tpStream = new ByteArrayOutputStreamWrapper(inResp.getOutputStream());
44         tpWriter = new PrintWriter JavaDoc(new OutputStreamWriter JavaDoc(tpStream,"UTF-8"));
45     }
46
47     public ServletOutputStream JavaDoc getOutputStream()
48     throws java.io.IOException JavaDoc
49     {
50         return tpStream;
51     }
52
53     public PrintWriter JavaDoc getWriter() throws java.io.IOException JavaDoc
54     {
55         return tpWriter;
56     }
57      
58     /** Get a String representation of the entire buffer.
59      */

60     public String JavaDoc toString()
61     {
62         return tpStream.getByteArrayStream().toString();
63     }
64     
65     public ByteArrayOutputStream JavaDoc getByteArrayOutputStream()
66     throws java.io.IOException JavaDoc
67     {
68         return tpStream.getByteArrayStream();
69     }
70 }
71
Popular Tags