1 |
/* PrintStream.java -- OutputStream for printing output |
/* PrintStream.java -- OutputStream for printing output |
2 |
Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. |
Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005 |
3 |
|
Free Software Foundation, Inc. |
4 |
|
|
5 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
6 |
|
|
83 |
private boolean closed; |
private boolean closed; |
84 |
|
|
85 |
/** |
/** |
86 |
|
* This class exists to forward the write calls from the PrintWriter back |
87 |
|
* to us. This is required to make subclassing of PrintStream work |
88 |
|
* correctly. |
89 |
|
*/ |
90 |
|
private class ForwardStream extends OutputStream |
91 |
|
{ |
92 |
|
public void close () throws IOException |
93 |
|
{ |
94 |
|
out.close (); |
95 |
|
} |
96 |
|
|
97 |
|
public void flush () throws IOException |
98 |
|
{ |
99 |
|
out.flush (); |
100 |
|
} |
101 |
|
|
102 |
|
public void write (byte[] b) throws IOException |
103 |
|
{ |
104 |
|
PrintStream.this.write (b); |
105 |
|
} |
106 |
|
|
107 |
|
public void write (byte[] b, int off, int len) throws IOException |
108 |
|
{ |
109 |
|
PrintStream.this.write (b, off, len); |
110 |
|
} |
111 |
|
|
112 |
|
public void write (int b) throws IOException |
113 |
|
{ |
114 |
|
PrintStream.this.write (b); |
115 |
|
} |
116 |
|
} |
117 |
|
|
118 |
|
/** |
119 |
* This method intializes a new <code>PrintStream</code> object to write |
* This method intializes a new <code>PrintStream</code> object to write |
120 |
* to the specified output sink. |
* to the specified output sink. |
121 |
* |
* |
143 |
{ |
{ |
144 |
super (out); |
super (out); |
145 |
|
|
146 |
pw = new PrintWriter (out, auto_flush); |
// FIXME Instead of using PrintWriter and ForwardStream we |
147 |
|
// should inline the character conversion (see libgcj's version |
148 |
|
// of this class) |
149 |
|
pw = new PrintWriter (new ForwardStream (), auto_flush); |
150 |
this.auto_flush = auto_flush; |
this.auto_flush = auto_flush; |
151 |
} |
} |
152 |
|
|
170 |
{ |
{ |
171 |
super (out); |
super (out); |
172 |
|
|
173 |
pw = new PrintWriter (new OutputStreamWriter (out, encoding), auto_flush); |
// FIXME Instead of using PrintWriter and ForwardStream we |
174 |
|
// should inline the character conversion (see libgcj's version |
175 |
|
// of this class) |
176 |
|
pw = new PrintWriter ( |
177 |
|
new OutputStreamWriter ( |
178 |
|
new ForwardStream (), encoding), auto_flush); |
179 |
this.auto_flush = auto_flush; |
this.auto_flush = auto_flush; |
180 |
} |
} |
181 |
|
|
513 |
if (auto_flush && (oneByte == '\n')) |
if (auto_flush && (oneByte == '\n')) |
514 |
flush (); |
flush (); |
515 |
} |
} |
516 |
|
catch (InterruptedIOException iioe) |
517 |
|
{ |
518 |
|
Thread.currentThread ().interrupt (); |
519 |
|
} |
520 |
catch (IOException e) |
catch (IOException e) |
521 |
{ |
{ |
522 |
setError (); |
setError (); |
544 |
if (auto_flush) |
if (auto_flush) |
545 |
flush (); |
flush (); |
546 |
} |
} |
547 |
|
catch (InterruptedIOException iioe) |
548 |
|
{ |
549 |
|
Thread.currentThread ().interrupt (); |
550 |
|
} |
551 |
catch (IOException e) |
catch (IOException e) |
552 |
{ |
{ |
553 |
setError (); |
setError (); |