|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ServletOutputStream.java | 0% | 0% | 0% | 0% |
|
1 | /* | |
2 | * Copyright 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 | package javax.servlet; | |
17 | ||
18 | import java.io.OutputStream; | |
19 | import java.io.IOException; | |
20 | import java.io.CharConversionException; | |
21 | import java.text.MessageFormat; | |
22 | import java.util.ResourceBundle; | |
23 | ||
24 | /** | |
25 | * Provides an output stream for sending binary data to the | |
26 | * client. A <code>ServletOutputStream</code> object is normally retrieved | |
27 | * via the {@link ServletResponse#getOutputStream} method. | |
28 | * | |
29 | * <p>This is an abstract class that the servlet container implements. | |
30 | * Subclasses of this class | |
31 | * must implement the <code>java.io.OutputStream.write(int)</code> | |
32 | * method. | |
33 | * | |
34 | * | |
35 | * @author Various | |
36 | * @version $Version$ | |
37 | * | |
38 | * @see ServletResponse | |
39 | * | |
40 | */ | |
41 | ||
42 | public abstract class ServletOutputStream extends OutputStream { | |
43 | ||
44 | private static final String LSTRING_FILE = "javax.servlet.LocalStrings"; | |
45 | private static ResourceBundle lStrings = | |
46 | ResourceBundle.getBundle(LSTRING_FILE); | |
47 | ||
48 | ||
49 | ||
50 | /** | |
51 | * | |
52 | * Does nothing, because this is an abstract class. | |
53 | * | |
54 | */ | |
55 | ||
56 | 0 | protected ServletOutputStream() { } |
57 | ||
58 | ||
59 | /** | |
60 | * Writes a <code>String</code> to the client, | |
61 | * without a carriage return-line feed (CRLF) | |
62 | * character at the end. | |
63 | * | |
64 | * | |
65 | * @param s the <code>String</code> to send to the client | |
66 | * | |
67 | * @exception IOException if an input or output exception occurred | |
68 | * | |
69 | */ | |
70 | ||
71 | 0 | public void print(String s) throws IOException { |
72 | 0 | if (s==null) s="null"; |
73 | 0 | int len = s.length(); |
74 | 0 | for (int i = 0; i < len; i++) { |
75 | 0 | char c = s.charAt (i); |
76 | ||
77 | // | |
78 | // XXX NOTE: This is clearly incorrect for many strings, | |
79 | // but is the only consistent approach within the current | |
80 | // servlet framework. It must suffice until servlet output | |
81 | // streams properly encode their output. | |
82 | // | |
83 | 0 | if ((c & 0xff00) != 0) { // high order byte must be zero |
84 | 0 | String errMsg = lStrings.getString("err.not_iso8859_1"); |
85 | 0 | Object[] errArgs = new Object[1]; |
86 | 0 | errArgs[0] = new Character(c); |
87 | 0 | errMsg = MessageFormat.format(errMsg, errArgs); |
88 | 0 | throw new CharConversionException(errMsg); |
89 | } | |
90 | 0 | write (c); |
91 | } | |
92 | } | |
93 | ||
94 | ||
95 | ||
96 | /** | |
97 | * Writes a <code>boolean</code> value to the client, | |
98 | * with no carriage return-line feed (CRLF) | |
99 | * character at the end. | |
100 | * | |
101 | * @param b the <code>boolean</code> value | |
102 | * to send to the client | |
103 | * | |
104 | * @exception IOException if an input or output exception occurred | |
105 | * | |
106 | */ | |
107 | ||
108 | 0 | public void print(boolean b) throws IOException { |
109 | 0 | String msg; |
110 | 0 | if (b) { |
111 | 0 | msg = lStrings.getString("value.true"); |
112 | } else { | |
113 | 0 | msg = lStrings.getString("value.false"); |
114 | } | |
115 | 0 | print(msg); |
116 | } | |
117 | ||
118 | ||
119 | ||
120 | /** | |
121 | * Writes a character to the client, | |
122 | * with no carriage return-line feed (CRLF) | |
123 | * at the end. | |
124 | * | |
125 | * @param c the character to send to the client | |
126 | * | |
127 | * @exception IOException if an input or output exception occurred | |
128 | * | |
129 | */ | |
130 | ||
131 | 0 | public void print(char c) throws IOException { |
132 | 0 | print(String.valueOf(c)); |
133 | } | |
134 | ||
135 | ||
136 | ||
137 | ||
138 | /** | |
139 | * | |
140 | * Writes an int to the client, | |
141 | * with no carriage return-line feed (CRLF) | |
142 | * at the end. | |
143 | * | |
144 | * @param i the int to send to the client | |
145 | * | |
146 | * @exception IOException if an input or output exception occurred | |
147 | * | |
148 | */ | |
149 | ||
150 | 0 | public void print(int i) throws IOException { |
151 | 0 | print(String.valueOf(i)); |
152 | } | |
153 | ||
154 | ||
155 | ||
156 | ||
157 | /** | |
158 | * | |
159 | * Writes a <code>long</code> value to the client, | |
160 | * with no carriage return-line feed (CRLF) at the end. | |
161 | * | |
162 | * @param l the <code>long</code> value | |
163 | * to send to the client | |
164 | * | |
165 | * @exception IOException if an input or output exception | |
166 | * occurred | |
167 | * | |
168 | */ | |
169 | ||
170 | 0 | public void print(long l) throws IOException { |
171 | 0 | print(String.valueOf(l)); |
172 | } | |
173 | ||
174 | ||
175 | ||
176 | /** | |
177 | * | |
178 | * Writes a <code>float</code> value to the client, | |
179 | * with no carriage return-line feed (CRLF) at the end. | |
180 | * | |
181 | * @param f the <code>float</code> value | |
182 | * to send to the client | |
183 | * | |
184 | * @exception IOException if an input or output exception occurred | |
185 | * | |
186 | * | |
187 | */ | |
188 | ||
189 | 0 | public void print(float f) throws IOException { |
190 | 0 | print(String.valueOf(f)); |
191 | } | |
192 | ||
193 | ||
194 | ||
195 | /** | |
196 | * | |
197 | * Writes a <code>double</code> value to the client, | |
198 | * with no carriage return-line feed (CRLF) at the end. | |
199 | * | |
200 | * @param d the <code>double</code> value | |
201 | * to send to the client | |
202 | * | |
203 | * @exception IOException if an input or output exception occurred | |
204 | * | |
205 | */ | |
206 | ||
207 | 0 | public void print(double d) throws IOException { |
208 | 0 | print(String.valueOf(d)); |
209 | } | |
210 | ||
211 | ||
212 | ||
213 | /** | |
214 | * Writes a carriage return-line feed (CRLF) | |
215 | * to the client. | |
216 | * | |
217 | * | |
218 | * | |
219 | * @exception IOException if an input or output exception occurred | |
220 | * | |
221 | */ | |
222 | ||
223 | 0 | public void println() throws IOException { |
224 | 0 | print("\r\n"); |
225 | } | |
226 | ||
227 | ||
228 | ||
229 | /** | |
230 | * Writes a <code>String</code> to the client, | |
231 | * followed by a carriage return-line feed (CRLF). | |
232 | * | |
233 | * | |
234 | * @param s the <code>String</code> to write to the client | |
235 | * | |
236 | * @exception IOException if an input or output exception occurred | |
237 | * | |
238 | */ | |
239 | ||
240 | 0 | public void println(String s) throws IOException { |
241 | 0 | print(s); |
242 | 0 | println(); |
243 | } | |
244 | ||
245 | ||
246 | ||
247 | ||
248 | /** | |
249 | * | |
250 | * Writes a <code>boolean</code> value to the client, | |
251 | * followed by a | |
252 | * carriage return-line feed (CRLF). | |
253 | * | |
254 | * | |
255 | * @param b the <code>boolean</code> value | |
256 | * to write to the client | |
257 | * | |
258 | * @exception IOException if an input or output exception occurred | |
259 | * | |
260 | */ | |
261 | ||
262 | 0 | public void println(boolean b) throws IOException { |
263 | 0 | print(b); |
264 | 0 | println(); |
265 | } | |
266 | ||
267 | ||
268 | ||
269 | /** | |
270 | * | |
271 | * Writes a character to the client, followed by a carriage | |
272 | * return-line feed (CRLF). | |
273 | * | |
274 | * @param c the character to write to the client | |
275 | * | |
276 | * @exception IOException if an input or output exception occurred | |
277 | * | |
278 | */ | |
279 | ||
280 | 0 | public void println(char c) throws IOException { |
281 | 0 | print(c); |
282 | 0 | println(); |
283 | } | |
284 | ||
285 | ||
286 | ||
287 | /** | |
288 | * | |
289 | * Writes an int to the client, followed by a | |
290 | * carriage return-line feed (CRLF) character. | |
291 | * | |
292 | * | |
293 | * @param i the int to write to the client | |
294 | * | |
295 | * @exception IOException if an input or output exception occurred | |
296 | * | |
297 | */ | |
298 | ||
299 | 0 | public void println(int i) throws IOException { |
300 | 0 | print(i); |
301 | 0 | println(); |
302 | } | |
303 | ||
304 | ||
305 | ||
306 | /** | |
307 | * | |
308 | * Writes a <code>long</code> value to the client, followed by a | |
309 | * carriage return-line feed (CRLF). | |
310 | * | |
311 | * | |
312 | * @param l the <code>long</code> value to write to the client | |
313 | * | |
314 | * @exception IOException if an input or output exception occurred | |
315 | * | |
316 | */ | |
317 | ||
318 | 0 | public void println(long l) throws IOException { |
319 | 0 | print(l); |
320 | 0 | println(); |
321 | } | |
322 | ||
323 | ||
324 | ||
325 | /** | |
326 | * | |
327 | * Writes a <code>float</code> value to the client, | |
328 | * followed by a carriage return-line feed (CRLF). | |
329 | * | |
330 | * @param f the <code>float</code> value | |
331 | * to write to the client | |
332 | * | |
333 | * | |
334 | * @exception IOException if an input or output exception | |
335 | * occurred | |
336 | * | |
337 | */ | |
338 | ||
339 | 0 | public void println(float f) throws IOException { |
340 | 0 | print(f); |
341 | 0 | println(); |
342 | } | |
343 | ||
344 | ||
345 | ||
346 | /** | |
347 | * | |
348 | * Writes a <code>double</code> value to the client, | |
349 | * followed by a carriage return-line feed (CRLF). | |
350 | * | |
351 | * | |
352 | * @param d the <code>double</code> value | |
353 | * to write to the client | |
354 | * | |
355 | * @exception IOException if an input or output exception occurred | |
356 | * | |
357 | */ | |
358 | ||
359 | 0 | public void println(double d) throws IOException { |
360 | 0 | print(d); |
361 | 0 | println(); |
362 | } | |
363 | } |
|