Commit 0003efa0 by Tom Tromey Committed by Tom Tromey

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
parent 5f82d4f2
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> 2001-04-02 Torsten Rueger <torsten.rueger@firsthop.com>
* java/text/MessageFormat.java (setLocale): Added missing `else'. * java/text/MessageFormat.java (setLocale): Added missing `else'.
......
// PrintStream.java - Print string representations // 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. This file is part of libgcj.
...@@ -18,7 +18,7 @@ import gnu.gcj.convert.UnicodeToBytes; ...@@ -18,7 +18,7 @@ import gnu.gcj.convert.UnicodeToBytes;
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
* "The Java Language Specification", ISBN 0-201-63451-1 * "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 class PrintStream extends FilterOutputStream
...@@ -29,6 +29,7 @@ public class PrintStream extends FilterOutputStream ...@@ -29,6 +29,7 @@ public class PrintStream extends FilterOutputStream
public boolean checkError () public boolean checkError ()
{ {
flush();
return error; return error;
} }
...@@ -36,8 +37,13 @@ public class PrintStream extends FilterOutputStream ...@@ -36,8 +37,13 @@ public class PrintStream extends FilterOutputStream
{ {
try try
{ {
flush();
out.close(); out.close();
} }
catch (InterruptedIOException iioe)
{
Thread.currentThread().interrupt();
}
catch (IOException e) catch (IOException e)
{ {
setError (); setError ();
...@@ -50,6 +56,10 @@ public class PrintStream extends FilterOutputStream ...@@ -50,6 +56,10 @@ public class PrintStream extends FilterOutputStream
{ {
out.flush(); out.flush();
} }
catch (InterruptedIOException iioe)
{
Thread.currentThread().interrupt();
}
catch (IOException e) catch (IOException e)
{ {
setError (); setError ();
...@@ -66,6 +76,10 @@ public class PrintStream extends FilterOutputStream ...@@ -66,6 +76,10 @@ public class PrintStream extends FilterOutputStream
if (auto_flush) if (auto_flush)
flush(); flush();
} }
catch (InterruptedIOException iioe)
{
Thread.currentThread().interrupt();
}
catch (IOException e) catch (IOException e)
{ {
setError (); setError ();
...@@ -83,32 +97,26 @@ public class PrintStream extends FilterOutputStream ...@@ -83,32 +97,26 @@ public class PrintStream extends FilterOutputStream
if (auto_flush) if (auto_flush)
flush(); flush();
} }
catch (InterruptedIOException iioe)
{
Thread.currentThread().interrupt();
}
catch (IOException e) catch (IOException e)
{ {
setError (); setError ();
} }
} }
/** Writes characters through to the inferior BufferedOutputStream. */
private void writeChars(char[] buf, int offset, int count) private void writeChars(char[] buf, int offset, int count)
throws IOException throws IOException
{ {
while (count > 0) while (count > 0)
{ {
// We must flush if out.count == out.buf.length. converter.setOutput(work_bytes, 0);
// 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);
int converted = converter.write(buf, offset, count); int converted = converter.write(buf, offset, count);
offset += converted; offset += converted;
count -= converted; count -= converted;
out.count = converter.count; out.write(work_bytes, 0, converter.count);
} }
} }
...@@ -117,20 +125,11 @@ public class PrintStream extends FilterOutputStream ...@@ -117,20 +125,11 @@ public class PrintStream extends FilterOutputStream
{ {
while (count > 0) while (count > 0)
{ {
// We must flush if out.count == out.buf.length. converter.setOutput(work_bytes, 0);
// 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);
int converted = converter.write(str, offset, count, work); int converted = converter.write(str, offset, count, work);
offset += converted; offset += converted;
count -= converted; count -= converted;
out.count = converter.count; out.write(work_bytes, 0, converter.count);
} }
} }
...@@ -239,15 +238,6 @@ public class PrintStream extends FilterOutputStream ...@@ -239,15 +238,6 @@ public class PrintStream extends FilterOutputStream
public PrintStream (OutputStream out, boolean af) public PrintStream (OutputStream out, boolean af)
{ {
super(out); 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(); converter = UnicodeToBytes.getDefaultEncoder();
error = false; error = false;
auto_flush = af; auto_flush = af;
...@@ -264,7 +254,11 @@ public class PrintStream extends FilterOutputStream ...@@ -264,7 +254,11 @@ public class PrintStream extends FilterOutputStream
{ {
out.write(oneByte); out.write(oneByte);
if (auto_flush && oneByte == '\n') if (auto_flush && oneByte == '\n')
out.flush(); flush();
}
catch (InterruptedIOException iioe)
{
Thread.currentThread().interrupt();
} }
catch (IOException e) catch (IOException e)
{ {
...@@ -278,7 +272,11 @@ public class PrintStream extends FilterOutputStream ...@@ -278,7 +272,11 @@ public class PrintStream extends FilterOutputStream
{ {
out.write(buffer, offset, count); out.write(buffer, offset, count);
if (auto_flush) if (auto_flush)
out.flush(); flush();
}
catch (InterruptedIOException iioe)
{
Thread.currentThread().interrupt();
} }
catch (IOException e) catch (IOException e)
{ {
...@@ -286,10 +284,12 @@ public class PrintStream extends FilterOutputStream ...@@ -286,10 +284,12 @@ public class PrintStream extends FilterOutputStream
} }
} }
BufferedOutputStream out;
UnicodeToBytes converter; UnicodeToBytes converter;
// Work buffer of characters for converter.
char[] work = new char[100]; 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. // True if error occurred.
private boolean error; private boolean error;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment