1 // PrintStream.java - Print string representations
3 /* Copyright (C) 1998, 1999, 2001 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
12 import gnu
.gcj
.convert
.UnicodeToBytes
;
15 * @author Tom Tromey <tromey@cygnus.com>
16 * @date September 24, 1998
19 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
20 * "The Java Language Specification", ISBN 0-201-63451-1
21 * Status: Believed complete and correct to 1.3
24 public class PrintStream
extends FilterOutputStream
26 /* Notice the implementation is quite similar to OutputStreamWriter.
27 * This leads to some minor duplication, because neither inherits
28 * from the other, and we want to maximize performance. */
30 public boolean checkError ()
43 catch (InterruptedIOException iioe
)
45 Thread
.currentThread().interrupt();
59 catch (InterruptedIOException iioe
)
61 Thread
.currentThread().interrupt();
69 private synchronized void print (String str
, boolean println
)
73 writeChars(str
, 0, str
.length());
75 writeChars(line_separator
, 0, line_separator
.length
);
79 catch (InterruptedIOException iioe
)
81 Thread
.currentThread().interrupt();
89 private synchronized void print (char[] chars
, int pos
, int len
,
94 writeChars(chars
, pos
, len
);
96 writeChars(line_separator
, 0, line_separator
.length
);
100 catch (InterruptedIOException iioe
)
102 Thread
.currentThread().interrupt();
104 catch (IOException e
)
110 private void writeChars(char[] buf
, int offset
, int count
)
115 converter
.setOutput(work_bytes
, 0);
116 int converted
= converter
.write(buf
, offset
, count
);
119 out
.write(work_bytes
, 0, converter
.count
);
123 private void writeChars(String str
, int offset
, int count
)
128 converter
.setOutput(work_bytes
, 0);
129 int converted
= converter
.write(str
, offset
, count
, work
);
132 out
.write(work_bytes
, 0, converter
.count
);
136 public void print (boolean bool
)
138 print(String
.valueOf(bool
), false);
141 public void print (int inum
)
143 print(String
.valueOf(inum
), false);
146 public void print (long lnum
)
148 print(String
.valueOf(lnum
), false);
151 public void print (float fnum
)
153 print(String
.valueOf(fnum
), false);
156 public void print (double dnum
)
158 print(String
.valueOf(dnum
), false);
161 public void print (Object obj
)
163 print(obj
== null ?
"null" : obj
.toString(), false);
166 public void print (String str
)
168 print(str
== null ?
"null" : str
, false);
171 public synchronized void print (char ch
)
174 print(work
, 0, 1, false);
177 public void print (char[] charArray
)
179 print(charArray
, 0, charArray
.length
, false);
182 public void println ()
184 print(line_separator
, 0, line_separator
.length
, false);
187 public void println (boolean bool
)
189 print(String
.valueOf(bool
), true);
192 public void println (int inum
)
194 print(String
.valueOf(inum
), true);
197 public void println (long lnum
)
199 print(String
.valueOf(lnum
), true);
202 public void println (float fnum
)
204 print(String
.valueOf(fnum
), true);
207 public void println (double dnum
)
209 print(String
.valueOf(dnum
), true);
212 public void println (Object obj
)
214 print(obj
== null ?
"null" : obj
.toString(), true);
217 public void println (String str
)
219 print (str
== null ?
"null" : str
, true);
222 public synchronized void println (char ch
)
225 print(work
, 0, 1, true);
228 public void println (char[] charArray
)
230 print(charArray
, 0, charArray
.length
, true);
233 public PrintStream (OutputStream out
)
238 public PrintStream (OutputStream out
, boolean af
)
241 converter
= UnicodeToBytes
.getDefaultEncoder();
246 protected void setError ()
251 public void write (int oneByte
)
256 if (auto_flush
&& oneByte
== '\n')
259 catch (InterruptedIOException iioe
)
261 Thread
.currentThread().interrupt();
263 catch (IOException e
)
269 public void write (byte[] buffer
, int offset
, int count
)
273 out
.write(buffer
, offset
, count
);
277 catch (InterruptedIOException iioe
)
279 Thread
.currentThread().interrupt();
281 catch (IOException e
)
287 UnicodeToBytes converter
;
289 // Work buffer of characters for converter.
290 char[] work
= new char[100];
291 // Work buffer of bytes where we temporarily keep converter output.
292 byte[] work_bytes
= new byte[100];
294 // True if error occurred.
295 private boolean error
;
296 // True if auto-flush.
297 private boolean auto_flush
;
299 // Line separator string.
300 private static final char[] line_separator
301 = System
.getProperty("line.separator").toCharArray();