KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > io > OutputStreamDevice


1 /*
2  * $Id: OutputStreamDevice.java,v 1.3 2004/12/01 07:54:08 hengels Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.io;
15
16 import java.io.IOException JavaDoc;
17 import java.io.OutputStream JavaDoc;
18 import java.io.PrintStream JavaDoc;
19
20 /**
21  * A Device encapsulating a ServletOutputStream
22  *
23  * @author <a HREF="mailto:hengels@to.com">Holger Engels</a>
24  * @version $Revision: 1.3 $
25  */

26 public final class OutputStreamDevice implements Device {
27     private PrintStream JavaDoc out;
28
29
30     public OutputStreamDevice(OutputStream JavaDoc out) {
31         this.out = new PrintStream JavaDoc(out);
32     }
33
34     public boolean isSizePreserving() { return true; }
35
36     /**
37      * Flush this Stream.
38      */

39     public void flush() throws IOException JavaDoc {
40         out.flush();
41     }
42
43     public void close() throws IOException JavaDoc {
44         out.close();
45     }
46
47     /**
48      * Print a String.
49      */

50     public Device print(String JavaDoc s) throws IOException JavaDoc {
51         if (s == null)
52             out.print("null");
53         else
54             out.print(s);
55         return this;
56     }
57
58     /**
59      * Print an integer.
60      */

61     public Device print(int i) throws IOException JavaDoc {
62         out.print(i);
63         return this;
64     }
65
66     /**
67      * Print any Object
68      */

69     public Device print(Object JavaDoc o) throws IOException JavaDoc {
70         if (o == null)
71             out.print("null");
72         else
73             out.print(o.toString());
74         return this;
75     }
76
77     /**
78      * Print a character.
79      */

80     public Device print(char c) throws IOException JavaDoc {
81         out.print(c);
82         return this;
83     }
84
85     /**
86      * Print an array of chars.
87      */

88     public Device print(char[] c) throws IOException JavaDoc {
89         return print(c, 0, c.length - 1);
90     }
91
92     /**
93      * Print a character array.
94      */

95     public Device print(char[] c, int start, int len) throws IOException JavaDoc {
96         final int end = start + len;
97         for (int i = start; i < end; ++i)
98             out.print(c[i]);
99         return this;
100     }
101
102     /**
103      * Writes the specified byte to this data output stream.
104      */

105     public Device write(int c) throws IOException JavaDoc {
106         out.write(c);
107         return this;
108     }
109
110     /**
111      * Writes b.length bytes from the specified byte array to this
112      * output stream.
113      */

114     public Device write(byte b[]) throws IOException JavaDoc {
115         out.write(b);
116         return this;
117     }
118
119     /**
120      * Writes len bytes from the specified byte array starting at offset
121      * off to this output stream.
122      */

123     public Device write(byte b[], int off, int len) throws IOException JavaDoc {
124         out.write(b, off, len);
125         return this;
126     }
127 }
128
129
130
Popular Tags