PrintStream.java (out): Removed field.

* 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.

From-SVN: r41014
This commit is contained in:
Tom Tromey 2001-04-02 21:16:38 +00:00 committed by Tom Tromey
parent 5f82d4f21c
commit 0003efa0b3
2 changed files with 51 additions and 37 deletions

View File

@ -1,3 +1,17 @@
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'.

View File

@ -1,6 +1,6 @@
// 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.
@ -18,7 +18,7 @@ import gnu.gcj.convert.UnicodeToBytes;
/* 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
@ -29,6 +29,7 @@ public class PrintStream extends FilterOutputStream
public boolean checkError ()
{
flush();
return error;
}
@ -36,8 +37,13 @@ public class PrintStream extends FilterOutputStream
{
try
{
flush();
out.close();
}
catch (InterruptedIOException iioe)
{
Thread.currentThread().interrupt();
}
catch (IOException e)
{
setError ();
@ -50,6 +56,10 @@ public class PrintStream extends FilterOutputStream
{
out.flush();
}
catch (InterruptedIOException iioe)
{
Thread.currentThread().interrupt();
}
catch (IOException e)
{
setError ();
@ -66,6 +76,10 @@ public class PrintStream extends FilterOutputStream
if (auto_flush)
flush();
}
catch (InterruptedIOException iioe)
{
Thread.currentThread().interrupt();
}
catch (IOException e)
{
setError ();
@ -83,32 +97,26 @@ public class PrintStream extends FilterOutputStream
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);
}
}
@ -117,20 +125,11 @@ public class PrintStream extends FilterOutputStream
{
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);
}
}
@ -239,15 +238,6 @@ public class PrintStream extends FilterOutputStream
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;
@ -264,7 +254,11 @@ public class PrintStream extends FilterOutputStream
{
out.write(oneByte);
if (auto_flush && oneByte == '\n')
out.flush();
flush();
}
catch (InterruptedIOException iioe)
{
Thread.currentThread().interrupt();
}
catch (IOException e)
{
@ -278,7 +272,11 @@ public class PrintStream extends FilterOutputStream
{
out.write(buffer, offset, count);
if (auto_flush)
out.flush();
flush();
}
catch (InterruptedIOException iioe)
{
Thread.currentThread().interrupt();
}
catch (IOException e)
{
@ -286,10 +284,12 @@ public class PrintStream extends FilterOutputStream
}
}
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;