1 |
/* PrintStream.java -- OutputStream for printing output |
/* PrintStream.java -- OutputStream for printing output |
2 |
Copyright (C) 1998 Free Software Foundation, Inc. |
Copyright (C) 1998,2003 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
54 |
* |
* |
55 |
* @deprecated |
* @deprecated |
56 |
* |
* |
|
* @version 0.0 |
|
|
* |
|
57 |
* @author Aaron M. Renn (arenn@urbanophile.com) |
* @author Aaron M. Renn (arenn@urbanophile.com) |
58 |
*/ |
*/ |
59 |
public class PrintStream extends FilterOutputStream |
public class PrintStream extends FilterOutputStream |
60 |
{ |
{ |
61 |
|
|
62 |
/* |
/* |
63 |
* Ok, why is this class deprecated? It could easily have been extended |
* Ok, why is this class deprecated? It could easily have been extended |
64 |
* to support character encodings. In fact, PrintWriter is basically a |
* to support character encodings. In fact, PrintWriter is basically a |
65 |
* superset of this except for the write() methods. So let's do something |
* superset of this except for the write() methods. So let's do something |
66 |
* tricky here and just redirect calls in this class to a hidden PrintWriter |
* tricky here and just redirect calls in this class to a hidden PrintWriter |
67 |
* instance. All the functionality goes there since that is the 'real' |
* instance. All the functionality goes there since that is the 'real' |
68 |
* class. The big win of doing this way is that the default character |
* class. The big win of doing this way is that the default character |
69 |
* encoding is done automagicially by the PrintWriter tree! |
* encoding is done automagicially by the PrintWriter tree! |
70 |
*/ |
*/ |
71 |
|
|
72 |
/*************************************************************************/ |
/*************************************************************************/ |
73 |
|
|
74 |
/* |
/* |
75 |
* Instance Variables |
* Instance Variables |
76 |
*/ |
*/ |
77 |
|
|
78 |
/** |
/** |
79 |
* This boolean indicates whether or not an error has ever occured |
* This boolean indicates whether or not an error has ever occured |
80 |
* on this stream. |
* on this stream. |
81 |
*/ |
*/ |
82 |
private boolean error_occurred; |
private boolean error_occurred; |
83 |
|
|
84 |
/** |
/** |
85 |
* This is <code>true</code> if auto-flush is enabled, <code>false</code> otherwise |
* This is <code>true</code> if auto-flush is enabled, |
86 |
*/ |
* <code>false</code> otherwise |
87 |
private boolean auto_flush; |
*/ |
88 |
|
private boolean auto_flush; |
89 |
/** |
|
90 |
* The PrintWriter instance this object writes to |
/** |
91 |
*/ |
* The PrintWriter instance this object writes to |
92 |
private PrintWriter pw; |
*/ |
93 |
|
private PrintWriter pw; |
94 |
/** |
|
95 |
* Lets us know if the stream is closed |
/** |
96 |
*/ |
* Lets us know if the stream is closed |
97 |
private boolean closed; |
*/ |
98 |
|
private boolean closed; |
99 |
/*************************************************************************/ |
|
100 |
|
/*************************************************************************/ |
101 |
/* |
|
102 |
* Constructors |
/* |
103 |
*/ |
* Constructors |
104 |
|
*/ |
105 |
/** |
|
106 |
* This method intializes a new <code>PrintStream</code> object to write |
/** |
107 |
* to the specified output sink. Note that this class is deprecated in |
* This method intializes a new <code>PrintStream</code> object to write |
108 |
* favor of <code>PrintWriter</code>. |
* to the specified output sink. Note that this class is deprecated in |
109 |
* |
* favor of <code>PrintWriter</code>. |
110 |
* @param out The <code>OutputStream</code> to write to. |
* |
111 |
* |
* @param out The <code>OutputStream</code> to write to. |
112 |
* @deprecated |
* |
113 |
*/ |
* @deprecated |
114 |
public |
*/ |
115 |
PrintStream(OutputStream out) |
public PrintStream(OutputStream out) |
116 |
{ |
{ |
117 |
this(out, false); |
this(out, false); |
118 |
} |
} |
119 |
|
|
120 |
/*************************************************************************/ |
/*************************************************************************/ |
121 |
|
|
122 |
/** |
/** |
123 |
* This method intializes a new <code>PrintStream</code> object to write |
* This method intializes a new <code>PrintStream</code> object to write |
124 |
* to the specified output sink. This constructor also allows "auto-flush" |
* to the specified output sink. This constructor also allows "auto-flush" |
125 |
* functionality to be specified where the stream will be flushed after |
* functionality to be specified where the stream will be flushed after |
126 |
* every line is terminated or newline character is written. |
* every line is terminated or newline character is written. |
127 |
* <p> |
* <p> |
128 |
* Note that this class is deprecated in favor of <code>PrintWriter</code>. |
* Note that this class is deprecated in favor of <code>PrintWriter</code>. |
129 |
* |
* |
130 |
* @param out The <code>OutputStream</code> to write to. |
* @param out The <code>OutputStream</code> to write to. |
131 |
* @param auto_flush <code>true</code> to flush the stream after every line, <code>false</code> otherwise |
* @param auto_flush <code>true</code> to flush the stream after every |
132 |
* |
* line, <code>false</code> otherwise |
133 |
* @deprecated |
* |
134 |
*/ |
* @deprecated |
135 |
public |
*/ |
136 |
PrintStream(OutputStream out, boolean auto_flush) |
public PrintStream(OutputStream out, boolean auto_flush) |
137 |
{ |
{ |
138 |
super(out); |
super(out); |
139 |
|
|
140 |
pw = new PrintWriter(out, auto_flush); |
pw = new PrintWriter(out, auto_flush); |
141 |
this.auto_flush = auto_flush; |
this.auto_flush = auto_flush; |
142 |
} |
} |
143 |
|
|
144 |
/*************************************************************************/ |
/*************************************************************************/ |
145 |
|
|
146 |
/* |
/* |
147 |
* Instance Methods |
* Instance Methods |
148 |
*/ |
*/ |
149 |
|
|
150 |
/** |
/** |
151 |
* This method checks to see if an error has occurred on this stream. Note |
* This method checks to see if an error has occurred on this stream. Note |
152 |
* that once an error has occurred, this method will continue to report |
* that once an error has occurred, this method will continue to report |
153 |
* <code>true</code> forever for this stream. Before checking for an |
* <code>true</code> forever for this stream. Before checking for an |
154 |
* error condition, this method flushes the stream. |
* error condition, this method flushes the stream. |
155 |
* |
* |
156 |
* @return <code>true</code> if an error has occurred, <code>false</code> otherwise |
* @return <code>true</code> if an error has occurred, |
157 |
*/ |
* <code>false</code> otherwise |
158 |
public boolean |
*/ |
159 |
checkError() |
public boolean checkError() |
160 |
{ |
{ |
161 |
if (!closed) |
if (!closed) |
162 |
|
pw.flush(); |
163 |
|
|
164 |
|
if (pw.checkError() | error_occurred) |
165 |
|
return(true); |
166 |
|
else |
167 |
|
return(false); |
168 |
|
} |
169 |
|
|
170 |
|
/*************************************************************************/ |
171 |
|
|
172 |
|
/** |
173 |
|
* This method can be called by subclasses to indicate that an error |
174 |
|
* has occurred and should be reported by <code>checkError</code>. |
175 |
|
*/ |
176 |
|
protected void setError() |
177 |
|
{ |
178 |
|
error_occurred = true; |
179 |
|
} |
180 |
|
|
181 |
|
/*************************************************************************/ |
182 |
|
|
183 |
|
/** |
184 |
|
* This method closes this stream and all underlying streams. |
185 |
|
*/ |
186 |
|
public synchronized void close() |
187 |
|
{ |
188 |
|
pw.close(); |
189 |
|
closed = true; |
190 |
|
} |
191 |
|
|
192 |
|
/*************************************************************************/ |
193 |
|
|
194 |
|
/** |
195 |
|
* This method flushes any buffered bytes to the underlying stream and |
196 |
|
* then flushes that stream as well. |
197 |
|
*/ |
198 |
|
public void flush() |
199 |
|
{ |
200 |
pw.flush(); |
pw.flush(); |
201 |
|
} |
202 |
|
|
203 |
if (pw.checkError() | error_occurred) |
/*************************************************************************/ |
|
return(true); |
|
|
else |
|
|
return(false); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method can be called by subclasses to indicate that an error |
|
|
* has occurred and should be reported by <code>checkError</code>. |
|
|
*/ |
|
|
protected void |
|
|
setError() |
|
|
{ |
|
|
error_occurred = true; |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method closes this stream and all underlying streams. |
|
|
*/ |
|
|
public synchronized void |
|
|
close() |
|
|
{ |
|
|
pw.close(); |
|
|
closed = true; |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method flushes any buffered bytes to the underlying stream and |
|
|
* then flushes that stream as well. |
|
|
*/ |
|
|
public void |
|
|
flush() |
|
|
{ |
|
|
pw.flush(); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This methods prints a boolean value to the stream. <code>true</code> |
|
|
* values are printed as "true" and <code>false</code> values are printed |
|
|
* as "false". |
|
|
* |
|
|
* @param b The <code>boolean</code> value to print |
|
|
*/ |
|
|
public void |
|
|
print(boolean b) |
|
|
{ |
|
|
pw.print(b); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints a char to the stream. The actual value printed is |
|
|
* determined by the character encoding in use. |
|
|
* |
|
|
* @param c The <code>char</code> value to be printed |
|
|
*/ |
|
|
public void |
|
|
print(char c) |
|
|
{ |
|
|
pw.print(c); |
|
|
|
|
|
if (auto_flush) |
|
|
if ((c == '\r') || (c == '\n')) |
|
|
flush(); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints an integer to the stream. The value printed is |
|
|
* determined using the <code>String.valueOf()</code> method. |
|
|
* |
|
|
* @param i The <code>int</code> value to be printed |
|
|
*/ |
|
|
public void |
|
|
print(int i) |
|
|
{ |
|
|
pw.print(i); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints a long to the stream. The value printed is |
|
|
* determined using the <code>String.valueOf()</code> method. |
|
|
* |
|
|
* @param l The <code>long</code> value to be printed |
|
|
*/ |
|
|
public void |
|
|
print(long l) |
|
|
{ |
|
|
pw.print(l); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints a float to the stream. The value printed is |
|
|
* determined using the <code>String.valueOf()</code> method. |
|
|
* |
|
|
* @param f The <code>float</code> value to be printed |
|
|
*/ |
|
|
public void |
|
|
print(float f) |
|
|
{ |
|
|
pw.print(f); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints a double to the stream. The value printed is |
|
|
* determined using the <code>String.valueOf()</code> method. |
|
|
* |
|
|
* @param d The <code>double</code> value to be printed |
|
|
*/ |
|
|
public void |
|
|
print(double d) |
|
|
{ |
|
|
pw.print(d); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints an array of characters to the stream. The actual |
|
|
* value printed depends on the system default encoding. |
|
|
* |
|
|
* @param s The array of characters to print. |
|
|
*/ |
|
|
public void |
|
|
print(char[] s) |
|
|
{ |
|
|
pw.print(s); |
|
|
|
|
|
if (auto_flush) |
|
|
for (int i = 0; i < s.length; i++) |
|
|
if ((s[i] == '\r') || (s[i] == '\n')) |
|
|
{ |
|
|
flush(); |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints a <code>String</code> to the stream. The actual |
|
|
* value printed depends on the system default encoding. |
|
|
* |
|
|
* @param s The <code>String</code> to print. |
|
|
*/ |
|
|
public void |
|
|
print(String s) |
|
|
{ |
|
|
pw.print(s); |
|
|
|
|
|
if (auto_flush) |
|
|
if ((s.indexOf('\r') != -1) || (s.indexOf('\n') != -1)) |
|
|
flush(); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints an <code>Object</code> to the stream. The actual |
|
|
* value printed is determined by calling the <code>String.valueOf()</code> |
|
|
* method. |
|
|
* |
|
|
* @param obj The <code>Object</code> to print. |
|
|
*/ |
|
|
public void |
|
|
print(Object obj) |
|
|
{ |
|
|
// Don't call pw directly. Convert to String so we scan for newline |
|
|
// characters on auto-flush; |
|
|
print(String.valueOf(obj)); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints a line separator sequence to the stream. The value |
|
|
* printed is determined by the system property <xmp>line.separator</xmp> |
|
|
* and is not necessarily the Unix '\n' newline character. |
|
|
*/ |
|
|
public void |
|
|
println() |
|
|
{ |
|
|
pw.println(); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This methods prints a boolean value to the stream. <code>true</code> |
|
|
* values are printed as "true" and <code>false</code> values are printed |
|
|
* as "false". |
|
|
* <p> |
|
|
* This method prints a line termination sequence after printing the value. |
|
|
* |
|
|
* @param b The <code>boolean</code> value to print |
|
|
*/ |
|
|
public void |
|
|
println(boolean b) |
|
|
{ |
|
|
pw.println(b); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints a char to the stream. The actual value printed is |
|
|
* determined by the character encoding in use. |
|
|
* <p> |
|
|
* This method prints a line termination sequence after printing the value. |
|
|
* |
|
|
* @param c The <code>char</code> value to be printed |
|
|
*/ |
|
|
public void |
|
|
println(char c) |
|
|
{ |
|
|
pw.println(c); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints an integer to the stream. The value printed is |
|
|
* determined using the <code>String.valueOf()</code> method. |
|
|
* <p> |
|
|
* This method prints a line termination sequence after printing the value. |
|
|
* |
|
|
* @param i The <code>int</code> value to be printed |
|
|
*/ |
|
|
public void |
|
|
println(int i) |
|
|
{ |
|
|
pw.println(i); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints a long to the stream. The value printed is |
|
|
* determined using the <code>String.valueOf()</code> method. |
|
|
* <p> |
|
|
* This method prints a line termination sequence after printing the value. |
|
|
* |
|
|
* @param l The <code>long</code> value to be printed |
|
|
*/ |
|
|
public void |
|
|
println(long l) |
|
|
{ |
|
|
pw.println(l); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints a float to the stream. The value printed is |
|
|
* determined using the <code>String.valueOf()</code> method. |
|
|
* <p> |
|
|
* This method prints a line termination sequence after printing the value. |
|
|
* |
|
|
* @param f The <code>float</code> value to be printed |
|
|
*/ |
|
|
public void |
|
|
println(float f) |
|
|
{ |
|
|
pw.println(f); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints a double to the stream. The value printed is |
|
|
* determined using the <code>String.valueOf()</code> method. |
|
|
* <p> |
|
|
* This method prints a line termination sequence after printing the value. |
|
|
* |
|
|
* @param d The <code>double</code> value to be printed |
|
|
*/ |
|
|
public void |
|
|
println(double d) |
|
|
{ |
|
|
pw.println(d); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method prints an array of characters to the stream. The actual |
|
|
* value printed depends on the system default encoding. |
|
|
* <p> |
|
|
* This method prints a line termination sequence after printing the value. |
|
|
* |
|
|
* @param s The array of characters to print. |
|
|
*/ |
|
|
public void |
|
|
println(char[] s) |
|
|
{ |
|
|
pw.println(s); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
204 |
|
|
205 |
/** |
/** |
206 |
* This method prints a <code>String</code> to the stream. The actual |
* This methods prints a boolean value to the stream. <code>true</code> |
207 |
* value printed depends on the system default encoding. |
* values are printed as "true" and <code>false</code> values are printed |
208 |
* <p> |
* as "false". |
209 |
* This method prints a line termination sequence after printing the value. |
* |
210 |
* |
* @param b The <code>boolean</code> value to print |
211 |
* @param s The <code>String</code> to print. |
*/ |
212 |
*/ |
public void print(boolean b) |
213 |
public void |
{ |
214 |
println(String s) |
pw.print(b); |
215 |
{ |
} |
216 |
pw.println(s); |
|
217 |
} |
/*************************************************************************/ |
218 |
|
|
219 |
/*************************************************************************/ |
/** |
220 |
|
* This method prints a char to the stream. The actual value printed is |
221 |
/** |
* determined by the character encoding in use. |
222 |
* This method prints an <code>Object</code> to the stream. The actual |
* |
223 |
* value printed is determined by calling the <code>String.valueOf()</code> |
* @param c The <code>char</code> value to be printed |
224 |
* method. |
*/ |
225 |
* <p> |
public void print(char c) |
226 |
* This method prints a line termination sequence after printing the value. |
{ |
227 |
* |
pw.print(c); |
228 |
* @param obj The <code>Object</code> to print. |
|
229 |
*/ |
if (auto_flush) |
230 |
public void |
if ((c == '\r') || (c == '\n')) |
231 |
println(Object obj) |
flush(); |
232 |
{ |
} |
233 |
pw.println(obj); |
|
234 |
} |
/*************************************************************************/ |
235 |
|
|
236 |
/*************************************************************************/ |
/** |
237 |
|
* This method prints an integer to the stream. The value printed is |
238 |
/** |
* determined using the <code>String.valueOf()</code> method. |
239 |
* This method writes a byte of data to the stream. If auto-flush is |
* |
240 |
* enabled, printing a newline character will cause the stream to be |
* @param i The <code>int</code> value to be printed |
241 |
* flushed after the character is written. |
*/ |
242 |
* |
public void print(int i) |
243 |
* @param b The byte to be written |
{ |
244 |
*/ |
pw.print(i); |
245 |
public synchronized void |
} |
246 |
write(int b) |
|
247 |
{ |
/*************************************************************************/ |
248 |
// Sigh, we actually have to implement this method. Flush first so that |
|
249 |
// things get written in the right order. |
/** |
250 |
flush(); |
* This method prints a long to the stream. The value printed is |
251 |
|
* determined using the <code>String.valueOf()</code> method. |
252 |
try |
* |
253 |
{ |
* @param l The <code>long</code> value to be printed |
254 |
out.write(b); |
*/ |
255 |
|
public void print(long l) |
256 |
if (auto_flush) |
{ |
257 |
if ((b == '\n') || (b == '\n')) |
pw.print(l); |
258 |
flush(); |
} |
259 |
} |
|
260 |
catch(IOException e) |
/*************************************************************************/ |
261 |
{ |
|
262 |
error_occurred = true; |
/** |
263 |
} |
* This method prints a float to the stream. The value printed is |
264 |
} |
* determined using the <code>String.valueOf()</code> method. |
265 |
|
* |
266 |
/*************************************************************************/ |
* @param f The <code>float</code> value to be printed |
267 |
|
*/ |
268 |
/** |
public void print(float f) |
269 |
* This method writes <code>len</code> bytes from the specified array |
{ |
270 |
* starting at index <code>offset</code> into the array. |
pw.print(f); |
271 |
* |
} |
272 |
* @param buf The array of bytes to write |
|
273 |
* @param offset The index into the array to start writing from |
/*************************************************************************/ |
274 |
* @param len The number of bytes to write |
|
275 |
*/ |
/** |
276 |
public synchronized void |
* This method prints a double to the stream. The value printed is |
277 |
write(byte[] buf, int offset, int len) |
* determined using the <code>String.valueOf()</code> method. |
278 |
{ |
* |
279 |
// We actually have to implement this method too. Flush first so that |
* @param d The <code>double</code> value to be printed |
280 |
// things get written in the right order. |
*/ |
281 |
flush(); |
public void print(double d) |
282 |
|
{ |
283 |
try |
pw.print(d); |
284 |
{ |
} |
285 |
out.write(buf, offset, len); |
|
286 |
|
/*************************************************************************/ |
287 |
if (auto_flush) |
|
288 |
for (int i = offset; i < len; i++) |
/** |
289 |
if ((buf[i] == '\r') || (buf[i] == '\n')) |
* This method prints an array of characters to the stream. The actual |
290 |
{ |
* value printed depends on the system default encoding. |
291 |
flush(); |
* |
292 |
break; |
* @param s The array of characters to print. |
293 |
} |
*/ |
294 |
} |
public void print(char[] s) |
295 |
catch(IOException e) |
{ |
296 |
{ |
pw.print(s); |
297 |
error_occurred = true; |
|
298 |
} |
if (auto_flush) |
299 |
} |
for (int i = 0; i < s.length; i++) |
300 |
|
if ((s[i] == '\r') || (s[i] == '\n')) |
301 |
|
{ |
302 |
|
flush(); |
303 |
|
break; |
304 |
|
} |
305 |
|
} |
306 |
|
|
307 |
|
/*************************************************************************/ |
308 |
|
|
309 |
|
/** |
310 |
|
* This method prints a <code>String</code> to the stream. The actual |
311 |
|
* value printed depends on the system default encoding. |
312 |
|
* |
313 |
|
* @param s The <code>String</code> to print. |
314 |
|
*/ |
315 |
|
public void print(String s) |
316 |
|
{ |
317 |
|
pw.print(s); |
318 |
|
|
319 |
|
if (auto_flush) |
320 |
|
if ((s.indexOf('\r') != -1) || (s.indexOf('\n') != -1)) |
321 |
|
flush(); |
322 |
|
} |
323 |
|
|
324 |
|
/*************************************************************************/ |
325 |
|
|
326 |
|
/** |
327 |
|
* This method prints an <code>Object</code> to the stream. The actual |
328 |
|
* value printed is determined by calling the <code>String.valueOf()</code> |
329 |
|
* method. |
330 |
|
* |
331 |
|
* @param obj The <code>Object</code> to print. |
332 |
|
*/ |
333 |
|
public void print(Object obj) |
334 |
|
{ |
335 |
|
// Don't call pw directly. Convert to String so we scan for newline |
336 |
|
// characters on auto-flush; |
337 |
|
print(String.valueOf(obj)); |
338 |
|
} |
339 |
|
|
340 |
|
/*************************************************************************/ |
341 |
|
|
342 |
|
/** |
343 |
|
* This method prints a line separator sequence to the stream. The value |
344 |
|
* printed is determined by the system property <xmp>line.separator</xmp> |
345 |
|
* and is not necessarily the Unix '\n' newline character. |
346 |
|
*/ |
347 |
|
public void println() |
348 |
|
{ |
349 |
|
pw.println(); |
350 |
|
} |
351 |
|
|
352 |
|
/*************************************************************************/ |
353 |
|
|
354 |
|
/** |
355 |
|
* This methods prints a boolean value to the stream. <code>true</code> |
356 |
|
* values are printed as "true" and <code>false</code> values are printed |
357 |
|
* as "false". |
358 |
|
* <p> |
359 |
|
* This method prints a line termination sequence after printing the value. |
360 |
|
* |
361 |
|
* @param b The <code>boolean</code> value to print |
362 |
|
*/ |
363 |
|
public void println(boolean b) |
364 |
|
{ |
365 |
|
pw.println(b); |
366 |
|
} |
367 |
|
|
368 |
|
/*************************************************************************/ |
369 |
|
|
370 |
|
/** |
371 |
|
* This method prints a char to the stream. The actual value printed is |
372 |
|
* determined by the character encoding in use. |
373 |
|
* <p> |
374 |
|
* This method prints a line termination sequence after printing the value. |
375 |
|
* |
376 |
|
* @param c The <code>char</code> value to be printed |
377 |
|
*/ |
378 |
|
public void println(char c) |
379 |
|
{ |
380 |
|
pw.println(c); |
381 |
|
} |
382 |
|
|
383 |
|
/*************************************************************************/ |
384 |
|
|
385 |
|
/** |
386 |
|
* This method prints an integer to the stream. The value printed is |
387 |
|
* determined using the <code>String.valueOf()</code> method. |
388 |
|
* <p> |
389 |
|
* This method prints a line termination sequence after printing the value. |
390 |
|
* |
391 |
|
* @param i The <code>int</code> value to be printed |
392 |
|
*/ |
393 |
|
public void println(int i) |
394 |
|
{ |
395 |
|
pw.println(i); |
396 |
|
} |
397 |
|
|
398 |
|
/*************************************************************************/ |
399 |
|
|
400 |
|
/** |
401 |
|
* This method prints a long to the stream. The value printed is |
402 |
|
* determined using the <code>String.valueOf()</code> method. |
403 |
|
* <p> |
404 |
|
* This method prints a line termination sequence after printing the value. |
405 |
|
* |
406 |
|
* @param l The <code>long</code> value to be printed |
407 |
|
*/ |
408 |
|
public void println(long l) |
409 |
|
{ |
410 |
|
pw.println(l); |
411 |
|
} |
412 |
|
|
413 |
|
/*************************************************************************/ |
414 |
|
|
415 |
|
/** |
416 |
|
* This method prints a float to the stream. The value printed is |
417 |
|
* determined using the <code>String.valueOf()</code> method. |
418 |
|
* <p> |
419 |
|
* This method prints a line termination sequence after printing the value. |
420 |
|
* |
421 |
|
* @param f The <code>float</code> value to be printed |
422 |
|
*/ |
423 |
|
public void println(float f) |
424 |
|
{ |
425 |
|
pw.println(f); |
426 |
|
} |
427 |
|
|
428 |
|
/*************************************************************************/ |
429 |
|
|
430 |
|
/** |
431 |
|
* This method prints a double to the stream. The value printed is |
432 |
|
* determined using the <code>String.valueOf()</code> method. |
433 |
|
* <p> |
434 |
|
* This method prints a line termination sequence after printing the value. |
435 |
|
* |
436 |
|
* @param d The <code>double</code> value to be printed |
437 |
|
*/ |
438 |
|
public void println(double d) |
439 |
|
{ |
440 |
|
pw.println(d); |
441 |
|
} |
442 |
|
|
443 |
|
/*************************************************************************/ |
444 |
|
|
445 |
|
/** |
446 |
|
* This method prints an array of characters to the stream. The actual |
447 |
|
* value printed depends on the system default encoding. |
448 |
|
* <p> |
449 |
|
* This method prints a line termination sequence after printing the value. |
450 |
|
* |
451 |
|
* @param s The array of characters to print. |
452 |
|
*/ |
453 |
|
public void println(char[] s) |
454 |
|
{ |
455 |
|
pw.println(s); |
456 |
|
} |
457 |
|
|
458 |
|
/*************************************************************************/ |
459 |
|
|
460 |
|
/** |
461 |
|
* This method prints a <code>String</code> to the stream. The actual |
462 |
|
* value printed depends on the system default encoding. |
463 |
|
* <p> |
464 |
|
* This method prints a line termination sequence after printing the value. |
465 |
|
* |
466 |
|
* @param s The <code>String</code> to print. |
467 |
|
*/ |
468 |
|
public void println(String s) |
469 |
|
{ |
470 |
|
pw.println(s); |
471 |
|
} |
472 |
|
|
473 |
|
/*************************************************************************/ |
474 |
|
|
475 |
|
/** |
476 |
|
* This method prints an <code>Object</code> to the stream. The actual |
477 |
|
* value printed is determined by calling the <code>String.valueOf()</code> |
478 |
|
* method. |
479 |
|
* <p> |
480 |
|
* This method prints a line termination sequence after printing the value. |
481 |
|
* |
482 |
|
* @param obj The <code>Object</code> to print. |
483 |
|
*/ |
484 |
|
public void println(Object obj) |
485 |
|
{ |
486 |
|
pw.println(obj); |
487 |
|
} |
488 |
|
|
489 |
|
/*************************************************************************/ |
490 |
|
|
491 |
|
/** |
492 |
|
* This method writes a byte of data to the stream. If auto-flush is |
493 |
|
* enabled, printing a newline character will cause the stream to be |
494 |
|
* flushed after the character is written. |
495 |
|
* |
496 |
|
* @param b The byte to be written |
497 |
|
*/ |
498 |
|
public synchronized void write(int b) |
499 |
|
{ |
500 |
|
// Sigh, we actually have to implement this method. Flush first so that |
501 |
|
// things get written in the right order. |
502 |
|
flush(); |
503 |
|
|
504 |
|
try |
505 |
|
{ |
506 |
|
out.write(b); |
507 |
|
|
508 |
|
if (auto_flush) |
509 |
|
if ((b == '\n') || (b == '\n')) |
510 |
|
flush(); |
511 |
|
} |
512 |
|
catch(IOException e) |
513 |
|
{ |
514 |
|
error_occurred = true; |
515 |
|
} |
516 |
|
} |
517 |
|
|
518 |
|
/*************************************************************************/ |
519 |
|
|
520 |
|
/** |
521 |
|
* This method writes <code>len</code> bytes from the specified array |
522 |
|
* starting at index <code>offset</code> into the array. |
523 |
|
* |
524 |
|
* @param buf The array of bytes to write |
525 |
|
* @param offset The index into the array to start writing from |
526 |
|
* @param len The number of bytes to write |
527 |
|
*/ |
528 |
|
public synchronized void write(byte[] buf, int offset, int len) |
529 |
|
{ |
530 |
|
// We actually have to implement this method too. Flush first so that |
531 |
|
// things get written in the right order. |
532 |
|
flush(); |
533 |
|
|
534 |
|
try |
535 |
|
{ |
536 |
|
out.write(buf, offset, len); |
537 |
|
|
538 |
|
if (auto_flush) |
539 |
|
for (int i = offset; i < len; i++) |
540 |
|
if ((buf[i] == '\r') || (buf[i] == '\n')) |
541 |
|
{ |
542 |
|
flush(); |
543 |
|
break; |
544 |
|
} |
545 |
|
} |
546 |
|
catch(IOException e) |
547 |
|
{ |
548 |
|
error_occurred = true; |
549 |
|
} |
550 |
|
} |
551 |
|
|
552 |
} // class PrintStream |
} // class PrintStream |
553 |
|
|