KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > vfs > StreamPrintWriter


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.vfs;
30
31 import java.io.IOException JavaDoc;
32 import java.io.PrintWriter JavaDoc;
33 import java.io.StringWriter JavaDoc;
34 import java.io.Writer JavaDoc;
35 import java.util.logging.Level JavaDoc;
36 import java.util.logging.Logger JavaDoc;
37
38 /**
39  * A print writer which writes to a specific WriteStream.
40  */

41 public class StreamPrintWriter extends PrintWriter JavaDoc
42   implements FlushBuffer, EnclosedWriteStream {
43   private final static Logger JavaDoc log
44     = Logger.getLogger(PrintWriterImpl.class.getName());
45   
46   private final static char []_nullChars = "null".toCharArray();
47   private final static char []_newline = "\n".toCharArray();
48
49   private final static Writer JavaDoc _dummyWriter = new StringWriter();
50
51   private final WriteStream _out;
52
53   /**
54    * Creates a new PrintWriterImpl
55    */

56   public StreamPrintWriter(WriteStream out)
57   {
58     super((Writer JavaDoc) _dummyWriter);
59
60     _out = out;
61   }
62
63   /**
64    * Writes a character.
65    */

66   final public void write(int ch)
67   {
68     try {
69       _out.print((char) ch);
70     } catch (IOException JavaDoc e) {
71       log.log(Level.FINE, e.toString(), e);
72     }
73   }
74
75   /**
76    * Writes a character.
77    */

78   final public void write(char []buf, int offset, int length)
79   {
80     try {
81       _out.print(buf, offset, length);
82     } catch (IOException JavaDoc e) {
83       log.log(Level.FINE, e.toString(), e);
84     }
85   }
86
87   /**
88    * Writes a character buffer.
89    */

90   final public void write(char []buf)
91   {
92     try {
93       _out.print(buf, 0, buf.length);
94     } catch (IOException JavaDoc e) {
95       log.log(Level.FINE, e.toString(), e);
96     }
97   }
98
99   /**
100    * Writes a string
101    */

102   final public void write(String JavaDoc v)
103   {
104     try {
105       _out.print(v);
106     } catch (IOException JavaDoc e) {
107       log.log(Level.FINE, e.toString(), e);
108     }
109   }
110
111   /**
112    * Writes a string
113    */

114   final public void write(String JavaDoc v, int offset, int length)
115   {
116     try {
117       _out.print(v, offset, length);
118     } catch (IOException JavaDoc e) {
119       log.log(Level.FINE, e.toString(), e);
120     }
121   }
122
123   /**
124    * Prints a character.
125    */

126   final public void print(char ch)
127   {
128     try {
129       _out.print(ch);
130     } catch (IOException JavaDoc e) {
131       log.log(Level.FINE, e.toString(), e);
132     }
133   }
134
135   /**
136    * Prints an integer.
137    */

138   final public void print(int v)
139   {
140     try {
141       _out.print(v);
142     } catch (IOException JavaDoc e) {
143       log.log(Level.FINE, e.toString(), e);
144     }
145   }
146   
147   /**
148    * Prints a long.
149    */

150   final public void print(long v)
151   {
152     try {
153       _out.print(v);
154     } catch (IOException JavaDoc e) {
155       log.log(Level.FINE, e.toString(), e);
156     }
157   }
158   
159   /**
160    * Prints a double followed by a newline.
161    *
162    * @param v the value to print
163    */

164   final public void print(float v)
165   {
166     try {
167       _out.print(v);
168     } catch (IOException JavaDoc e) {
169       log.log(Level.FINE, e.toString(), e);
170     }
171   }
172   
173   /**
174    * Prints a double followed by a newline.
175    *
176    * @param v the value to print
177    */

178   final public void print(double v)
179   {
180     try {
181       _out.print(v);
182     } catch (IOException JavaDoc e) {
183       log.log(Level.FINE, e.toString(), e);
184     }
185   }
186
187   /**
188    * Prints a character array
189    */

190   final public void print(char []v)
191   {
192     try {
193       _out.print(v);
194     } catch (IOException JavaDoc e) {
195       log.log(Level.FINE, e.toString(), e);
196     }
197   }
198
199   /**
200    * Prints a string.
201    */

202   final public void print(String JavaDoc v)
203   {
204     try {
205       _out.print(v);
206     } catch (IOException JavaDoc e) {
207       log.log(Level.FINE, e.toString(), e);
208     }
209   }
210
211   /**
212    * Prints the value of the object.
213    */

214   final public void print(Object JavaDoc v)
215   {
216     try {
217       _out.print(v);
218     } catch (IOException JavaDoc e) {
219       log.log(Level.FINE, e.toString(), e);
220     }
221   }
222
223   /**
224    * Prints the newline.
225    */

226   final public void println()
227   {
228     try {
229       _out.println();
230     } catch (IOException JavaDoc e) {
231       log.log(Level.FINE, e.toString(), e);
232     }
233   }
234   
235   /**
236    * Prints the boolean followed by a newline.
237    *
238    * @param v the value to print
239    */

240   final public void println(boolean v)
241   {
242     try {
243       _out.println(v);
244     } catch (IOException JavaDoc e) {
245       log.log(Level.FINE, e.toString(), e);
246     }
247   }
248
249   /**
250    * Prints a character followed by a newline.
251    *
252    * @param v the value to print
253    */

254   final public void println(char v)
255   {
256     try {
257       _out.println(v);
258     } catch (IOException JavaDoc e) {
259       log.log(Level.FINE, e.toString(), e);
260     }
261   }
262   
263   /**
264    * Prints an integer followed by a newline.
265    *
266    * @param v the value to print
267    */

268   final public void println(int v)
269   {
270     try {
271       _out.println(v);
272     } catch (IOException JavaDoc e) {
273       log.log(Level.FINE, e.toString(), e);
274     }
275   }
276   
277   /**
278    * Prints a long followed by a newline.
279    *
280    * @param v the value to print
281    */

282   final public void println(long v)
283   {
284     try {
285       _out.println(v);
286     } catch (IOException JavaDoc e) {
287       log.log(Level.FINE, e.toString(), e);
288     }
289   }
290   
291   /**
292    * Prints a float followed by a newline.
293    *
294    * @param v the value to print
295    */

296   final public void println(float v)
297   {
298     try {
299       _out.println(v);
300     } catch (IOException JavaDoc e) {
301       log.log(Level.FINE, e.toString(), e);
302     }
303   }
304   
305   /**
306    * Prints a double followed by a newline.
307    *
308    * @param v the value to print
309    */

310   final public void println(double v)
311   {
312     try {
313       _out.println(v);
314     } catch (IOException JavaDoc e) {
315       log.log(Level.FINE, e.toString(), e);
316     }
317   }
318
319   /**
320    * Writes a character array followed by a newline.
321    */

322   final public void println(char []v)
323   {
324     try {
325       _out.println(v);
326     } catch (IOException JavaDoc e) {
327       log.log(Level.FINE, e.toString(), e);
328     }
329   }
330
331   /**
332    * Writes a string followed by a newline.
333    */

334   final public void println(String JavaDoc v)
335   {
336     try {
337       _out.println(v);
338     } catch (IOException JavaDoc e) {
339       log.log(Level.FINE, e.toString(), e);
340     }
341   }
342   
343   /**
344    * Writes an object followed by a newline.
345    */

346   final public void println(Object JavaDoc v)
347   {
348     try {
349       _out.println(v);
350     } catch (IOException JavaDoc e) {
351       log.log(Level.FINE, e.toString(), e);
352     }
353   }
354
355   /**
356    * Flushes the writer.
357    */

358   public void flush()
359   {
360     try {
361       _out.flush();
362     } catch (IOException JavaDoc e) {
363       log.log(Level.FINE, e.toString(), e);
364     }
365   }
366
367   /**
368    * Flushes the writer.
369    */

370   public void flushBuffer()
371   {
372     try {
373       _out.flushBuffer();
374     } catch (IOException JavaDoc e) {
375       log.log(Level.FINE, e.toString(), e);
376     }
377   }
378
379   public WriteStream getWriteStream()
380   {
381     return _out;
382   }
383
384   public void close()
385   {
386   }
387 }
388
Popular Tags