KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > connector > CoyoteWriter


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

17
18
19 package org.apache.catalina.connector;
20
21 import java.io.IOException JavaDoc;
22 import java.io.PrintWriter JavaDoc;
23
24 /**
25  * Coyote implementation of the servlet writer.
26  *
27  * @author Remy Maucherat
28  */

29 public class CoyoteWriter
30     extends PrintWriter JavaDoc {
31
32
33     // -------------------------------------------------------------- Constants
34

35
36     private static final char[] LINE_SEP = { '\r', '\n' };
37
38
39     // ----------------------------------------------------- Instance Variables
40

41
42     protected OutputBuffer ob;
43     protected boolean error = false;
44
45
46     // ----------------------------------------------------------- Constructors
47

48
49     public CoyoteWriter(OutputBuffer ob) {
50         super(ob);
51         this.ob = ob;
52     }
53
54
55     // --------------------------------------------------------- Public Methods
56

57
58     /**
59      * Prevent cloning the facade.
60      */

61     protected Object JavaDoc clone()
62         throws CloneNotSupportedException JavaDoc {
63         throw new CloneNotSupportedException JavaDoc();
64     }
65
66
67     // -------------------------------------------------------- Package Methods
68

69
70     /**
71      * Clear facade.
72      */

73     void clear() {
74         ob = null;
75     }
76
77
78     /**
79      * Recycle.
80      */

81     void recycle() {
82         error = false;
83     }
84
85
86     // --------------------------------------------------------- Writer Methods
87

88
89     public void flush() {
90
91         if (error)
92             return;
93
94         try {
95             ob.flush();
96         } catch (IOException JavaDoc e) {
97             error = true;
98         }
99
100     }
101
102
103     public void close() {
104
105         // We don't close the PrintWriter - super() is not called,
106
// so the stream can be reused. We close ob.
107
try {
108             ob.close();
109         } catch (IOException JavaDoc ex ) {
110             ;
111         }
112         error = false;
113
114     }
115
116
117     public boolean checkError() {
118         flush();
119         return error;
120     }
121
122
123     public void write(int c) {
124
125         if (error)
126             return;
127
128         try {
129             ob.write(c);
130         } catch (IOException JavaDoc e) {
131             error = true;
132         }
133
134     }
135
136
137     public void write(char buf[], int off, int len) {
138
139         if (error)
140             return;
141
142         try {
143             ob.write(buf, off, len);
144         } catch (IOException JavaDoc e) {
145             error = true;
146         }
147
148     }
149
150
151     public void write(char buf[]) {
152     write(buf, 0, buf.length);
153     }
154
155
156     public void write(String JavaDoc s, int off, int len) {
157
158         if (error)
159             return;
160
161         try {
162             ob.write(s, off, len);
163         } catch (IOException JavaDoc e) {
164             error = true;
165         }
166
167     }
168
169
170     public void write(String JavaDoc s) {
171         write(s, 0, s.length());
172     }
173
174
175     // ---------------------------------------------------- PrintWriter Methods
176

177
178     public void print(boolean b) {
179         if (b) {
180             write("true");
181         } else {
182             write("false");
183         }
184     }
185
186
187     public void print(char c) {
188         write(c);
189     }
190
191
192     public void print(int i) {
193         write(String.valueOf(i));
194     }
195
196
197     public void print(long l) {
198         write(String.valueOf(l));
199     }
200
201
202     public void print(float f) {
203         write(String.valueOf(f));
204     }
205
206
207     public void print(double d) {
208         write(String.valueOf(d));
209     }
210
211
212     public void print(char s[]) {
213         write(s);
214     }
215
216
217     public void print(String JavaDoc s) {
218         if (s == null) {
219             s = "null";
220         }
221         write(s);
222     }
223
224
225     public void print(Object JavaDoc obj) {
226         write(String.valueOf(obj));
227     }
228
229
230     public void println() {
231         write(LINE_SEP);
232     }
233
234
235     public void println(boolean b) {
236         print(b);
237         println();
238     }
239
240
241     public void println(char c) {
242         print(c);
243         println();
244     }
245
246
247     public void println(int i) {
248         print(i);
249         println();
250     }
251
252
253     public void println(long l) {
254         print(l);
255         println();
256     }
257
258
259     public void println(float f) {
260         print(f);
261         println();
262     }
263
264
265     public void println(double d) {
266         print(d);
267         println();
268     }
269
270
271     public void println(char c[]) {
272         print(c);
273         println();
274     }
275
276
277     public void println(String JavaDoc s) {
278         print(s);
279         println();
280     }
281
282
283     public void println(Object JavaDoc o) {
284         print(o);
285         println();
286     }
287
288
289 }
290
Popular Tags