+2001-04-02 Tom Tromey <tromey@redhat.com>
+
+ * java/io/PrintStream.java (out): Removed field. Fixes PR
+ java/2449.
+ (write): Call flush, not out.flush, per spec.
+ (close): Flush output stream, per spec. Handle
+ InterruptedIOException.
+ (checkError): Likewise.
+ (flush, print, write): Handle InterruptedIOException per spec.
+ (PrintStream): Don't create BufferedOutputStream.
+ (work_bytes): New field.
+ (writeChars): Use work_bytes. Don't assume `out' is a
+ BufferedOutputStream.
+
2001-04-02 Torsten Rueger <torsten.rueger@firsthop.com>
* java/text/MessageFormat.java (setLocale): Added missing `else'.
// PrintStream.java - Print string representations
-/* Copyright (C) 1998, 1999 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2001 Free Software Foundation
This file is part of libgcj.
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
* "The Java Language Specification", ISBN 0-201-63451-1
- * Status: Not finished.
+ * Status: Believed complete and correct to 1.3
*/
public class PrintStream extends FilterOutputStream
public boolean checkError ()
{
+ flush();
return error;
}
{
try
{
+ flush();
out.close();
}
+ catch (InterruptedIOException iioe)
+ {
+ Thread.currentThread().interrupt();
+ }
catch (IOException e)
{
setError ();
{
out.flush();
}
+ catch (InterruptedIOException iioe)
+ {
+ Thread.currentThread().interrupt();
+ }
catch (IOException e)
{
setError ();
if (auto_flush)
flush();
}
+ catch (InterruptedIOException iioe)
+ {
+ Thread.currentThread().interrupt();
+ }
catch (IOException e)
{
setError ();
if (auto_flush)
flush();
}
+ catch (InterruptedIOException iioe)
+ {
+ Thread.currentThread().interrupt();
+ }
catch (IOException e)
{
setError ();
}
}
- /** Writes characters through to the inferior BufferedOutputStream. */
private void writeChars(char[] buf, int offset, int count)
throws IOException
{
while (count > 0)
{
- // We must flush if out.count == out.buf.length.
- // It is probably a good idea to flush if out.buf is almost full.
- // This test is an approximation for "almost full".
- if (out.count + count >= out.buf.length)
- {
- out.flush();
- if (out.count != 0)
- throw new IOException("unable to flush output byte buffer");
- }
- converter.setOutput(out.buf, out.count);
+ converter.setOutput(work_bytes, 0);
int converted = converter.write(buf, offset, count);
offset += converted;
count -= converted;
- out.count = converter.count;
+ out.write(work_bytes, 0, converter.count);
}
}
{
while (count > 0)
{
- // We must flush if out.count == out.buf.length.
- // It is probably a good idea to flush if out.buf is almost full.
- // This test is an approximation for "almost full".
- if (out.count + count >= out.buf.length)
- {
- out.flush();
- if (out.count != 0)
- throw new IOException("unable to flush output byte buffer");
- }
- converter.setOutput(out.buf, out.count);
+ converter.setOutput(work_bytes, 0);
int converted = converter.write(str, offset, count, work);
offset += converted;
count -= converted;
- out.count = converter.count;
+ out.write(work_bytes, 0, converter.count);
}
}
public PrintStream (OutputStream out, boolean af)
{
super(out);
- if (out instanceof BufferedOutputStream)
- this.out = (BufferedOutputStream) out;
- else
- {
- this.out = new BufferedOutputStream(out, 250);
- /* PrintStream redefines "out". Explicitly reset FilterOutputStream's
- * "out" so that they're referring to the same thing. */
- super.out = this.out;
- }
converter = UnicodeToBytes.getDefaultEncoder();
error = false;
auto_flush = af;
{
out.write(oneByte);
if (auto_flush && oneByte == '\n')
- out.flush();
+ flush();
+ }
+ catch (InterruptedIOException iioe)
+ {
+ Thread.currentThread().interrupt();
}
catch (IOException e)
{
{
out.write(buffer, offset, count);
if (auto_flush)
- out.flush();
+ flush();
+ }
+ catch (InterruptedIOException iioe)
+ {
+ Thread.currentThread().interrupt();
}
catch (IOException e)
{
}
}
- BufferedOutputStream out;
UnicodeToBytes converter;
+ // Work buffer of characters for converter.
char[] work = new char[100];
+ // Work buffer of bytes where we temporarily keep converter output.
+ byte[] work_bytes = new byte[100];
// True if error occurred.
private boolean error;