KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > core > misc > InetOutputStream


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.core.misc;
66
67 /*
68  * InetOutputStream.java
69  *
70  * Copyright 1999, 2000, 2001 Jcorporate Ltd.
71  */

72
73 import java.io.BufferedOutputStream JavaDoc;
74 import java.io.FilterOutputStream JavaDoc;
75 import java.io.IOException JavaDoc;
76 import java.io.OutputStream JavaDoc;
77
78
79 /**
80  * @author Michaeel Nash
81  */

82 public class InetOutputStream
83         extends FilterOutputStream JavaDoc {
84     private boolean linemode;
85
86     /**
87      * Constructor
88      *
89      * @param out
90      */

91     public InetOutputStream(OutputStream JavaDoc out) {
92         this(out, true);
93     } /* InetOutputStream(OutputStream) */
94
95     /**
96      * Constructor
97      *
98      * @param out
99      * @param linemode
100      */

101     public InetOutputStream(OutputStream JavaDoc out, boolean linemode) {
102         super((out instanceof BufferedOutputStream JavaDoc)
103                 ? out : new BufferedOutputStream JavaDoc(out));
104         this.linemode = linemode;
105     } /* InetOutputStream(OutputStream, boolean) */
106
107     /**
108      * @return OutputStream
109      */

110     public OutputStream JavaDoc getOutputStream() {
111         return out;
112     } /* getOutputStream() */
113
114     /**
115      * @param a[]
116      */

117     synchronized public void print(char[] a)
118             throws IOException JavaDoc {
119         for (int i = 0; i < a.length; i++) {
120             write(a[i]);
121         }
122     } /* print(char) */
123
124
125     /**
126      * @param chr
127      */

128     public void print(char chr)
129             throws IOException JavaDoc {
130         print(String.valueOf(chr));
131     } /* print(char) */
132
133
134     /**
135      * @param dval
136      */

137     public void print(double dval)
138             throws IOException JavaDoc {
139         print(String.valueOf(dval));
140     } /* print(double) */
141
142
143     /**
144      * @param fval
145      */

146     public void print(float fval)
147             throws IOException JavaDoc {
148         print(String.valueOf(fval));
149     } /* print(float) */
150
151
152     /**
153      * @param i
154      */

155     public void print(int i)
156             throws IOException JavaDoc {
157         print(String.valueOf(i));
158     } /* print(int) */
159
160
161     /**
162      * @param lval
163      */

164     public void print(long lval)
165             throws IOException JavaDoc {
166         print(String.valueOf(lval));
167     } /* print(long) */
168
169
170     /**
171      * @param obj
172      */

173     public void print(Object JavaDoc obj)
174             throws IOException JavaDoc {
175         print(String.valueOf(obj));
176     } /* print(Object) */
177
178
179     /**
180      * @param str
181      */

182     synchronized public void print(String JavaDoc str)
183             throws IOException JavaDoc {
184         int length = str.length();
185
186         for (int i = 0; i < length; i++) {
187             write(str.charAt(i));
188         }
189     } /* print(String) */
190
191
192     /**
193      * @throws IOException
194      */

195     synchronized public void println()
196             throws IOException JavaDoc {
197         write('\r');
198         write('\n');
199     } /* println() */
200
201
202     /**
203      * @param a[]
204      */

205     synchronized public void println(char[] a)
206             throws IOException JavaDoc {
207         print(a);
208         println();
209     } /* println(char) */
210
211
212     /**
213      * @param chr
214      */

215     synchronized public void println(char chr)
216             throws IOException JavaDoc {
217         print(chr);
218         println();
219     } /* println(char) */
220
221
222     /**
223      * @param dval
224      */

225     synchronized public void println(double dval)
226             throws IOException JavaDoc {
227         print(dval);
228         println();
229     } /* println(double) */
230
231
232     /**
233      * @param fval
234      */

235     synchronized public void println(float fval)
236             throws IOException JavaDoc {
237         print(fval);
238         println();
239     } /* println(float) */
240
241
242     /**
243      * @param i
244      */

245     synchronized public void println(int i)
246             throws IOException JavaDoc {
247         print(i);
248         println();
249     } /* println(int) */
250
251
252     /**
253      * @param lval
254      */

255     synchronized public void println(long lval)
256             throws IOException JavaDoc {
257         print(lval);
258         println();
259     } /* println(long) */
260
261
262     /**
263      * @param obj
264      */

265     synchronized public void println(Object JavaDoc obj)
266             throws IOException JavaDoc {
267         print(obj);
268         println();
269     } /* println(Object) */
270
271
272     /**
273      * @param str
274      */

275     synchronized public void println(String JavaDoc str)
276             throws IOException JavaDoc {
277         System.out.println("S: " + str);
278         print(str);
279         println();
280     } /* println(String) */
281
282
283     /**
284      * @param flag
285      */

286     public void setLinemode(boolean flag) {
287         linemode = flag;
288     } /* setLinemode(boolean) */
289
290     /**
291      * @param i
292      */

293     public void write(int i)
294             throws IOException JavaDoc {
295         out.write(i);
296
297         if (linemode && (i == '\n')) {
298             out.flush();
299         }
300     } /* write(int) */
301
302
303 } /* InetOutputStream */
304
305 /* InetOutputStream */
Popular Tags