KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > transport > http > FilterPrintWriter


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not 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.
15  */

16
17 package org.apache.axis.transport.http;
18
19 import javax.servlet.http.HttpServletResponse JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.io.OutputStream JavaDoc;
22 import java.io.PrintWriter JavaDoc;
23
24 /**
25  * simple wrapper around PrintWriter class. It creates the PrintWriter
26  * object on demand, thus allowing to have a ResponseWriter class for
27  * structural reasons, while actually creating the writer on demand.
28  * This solves the problem of having to have a PrintWriter object available and being forced
29  * to set the contentType of the response object after creation.
30  *
31  * @author Davanum Srinivas (dims@yahoo.com)
32  */

33
34 public class FilterPrintWriter extends PrintWriter JavaDoc {
35
36     private PrintWriter JavaDoc _writer = null;
37     private HttpServletResponse JavaDoc _response = null;
38     private static OutputStream JavaDoc _sink = new NullOutputStream();
39
40     public FilterPrintWriter(HttpServletResponse JavaDoc aResponse) {
41         super(_sink);
42         _response = aResponse;
43     }
44
45     private PrintWriter JavaDoc getPrintWriter() {
46         if (_writer == null) {
47             try {
48                 _writer = _response.getWriter();
49             } catch (IOException JavaDoc e) {
50                 throw new RuntimeException JavaDoc(e.toString());
51             }
52         }
53         return _writer;
54     }
55
56     public void write(int i) {
57         getPrintWriter().write(i);
58     }
59
60     public void write(char[] chars) {
61         getPrintWriter().write(chars);
62     }
63
64     public void write(char[] chars, int i, int i1) {
65         getPrintWriter().write(chars, i, i1);
66     }
67
68     public void write(String JavaDoc string) {
69         getPrintWriter().write(string);
70     }
71
72     public void write(String JavaDoc string, int i, int i1) {
73         getPrintWriter().write(string, i, i1);
74     }
75
76     public void flush() {
77         getPrintWriter().flush();
78     }
79
80     public void close() {
81         getPrintWriter().close();
82     }
83
84     public boolean checkError() {
85         return getPrintWriter().checkError();
86     }
87
88     public void print(boolean b) {
89         getPrintWriter().print(b);
90     }
91
92     public void print(char c) {
93         getPrintWriter().print(c);
94     }
95
96     public void print(int i) {
97         getPrintWriter().print(i);
98     }
99
100     public void print(long l) {
101         getPrintWriter().print(l);
102     }
103
104     public void print(float v) {
105         getPrintWriter().print(v);
106     }
107
108     public void print(double v) {
109         getPrintWriter().print(v);
110     }
111
112     public void print(char[] chars) {
113         getPrintWriter().print(chars);
114     }
115
116     public void print(String JavaDoc string) {
117         getPrintWriter().print(string);
118     }
119
120     public void print(Object JavaDoc object) {
121         getPrintWriter().print(object);
122     }
123
124     public void println() {
125         getPrintWriter().println();
126     }
127
128     public void println(boolean b) {
129         getPrintWriter().println(b);
130     }
131
132     public void println(char c) {
133         getPrintWriter().println(c);
134     }
135
136     public void println(int i) {
137         getPrintWriter().println(i);
138     }
139
140     public void println(long l) {
141         getPrintWriter().println(l);
142     }
143
144     public void println(float v) {
145         getPrintWriter().println(v);
146     }
147
148     public void println(double v) {
149         getPrintWriter().println(v);
150     }
151
152     public void println(char[] chars) {
153         getPrintWriter().println(chars);
154     }
155
156     public void println(String JavaDoc string) {
157         getPrintWriter().println(string);
158     }
159
160     public void println(Object JavaDoc object) {
161         getPrintWriter().println(object);
162     }
163
164     static public class NullOutputStream extends OutputStream JavaDoc {
165         public void write(int b) {
166             // no code -- no output
167
}
168     }
169 }
170
Popular Tags