Commit b63853f9 by Bryce McKinlay Committed by Bryce McKinlay

re PR libgcj/11778 (System.out PrintStream does too much buffering)

	* java/io/PrintStream.java (print): Always flush if auto_flush is
	set. Don't check for newline characters.
	(write (int)): Implement without using a temporary array.
	(write (byte[], int, int): Always flush if auto_flush is set. Don't
	check for newline characters.
	Fixes PR libgcj/11778.

From-SVN: r70284
parent 62515d69
2003-08-10 Bryce McKinlay <bryce@mckinlay.net.nz>
* java/io/PrintStream.java (print): Always flush if auto_flush is
set. Don't check for newline characters.
(write (int)): Implement without using a temporary array.
(write (byte[], int, int): Always flush if auto_flush is set. Don't
check for newline characters.
Fixes PR libgcj/11778.
2003-08-08 Andrew Haley <aph@redhat.com> 2003-08-08 Andrew Haley <aph@redhat.com>
* Makefile.am (AM_CXXFLAGS): Define BOOT_CLASS_PATH. * Makefile.am (AM_CXXFLAGS): Define BOOT_CLASS_PATH.
......
...@@ -95,7 +95,9 @@ public class PrintStream extends FilterOutputStream ...@@ -95,7 +95,9 @@ public class PrintStream extends FilterOutputStream
* This method intializes a new <code>PrintStream</code> object to write * This method intializes a new <code>PrintStream</code> object to write
* to the specified output sink. This constructor also allows "auto-flush" * to the specified output sink. This constructor also allows "auto-flush"
* functionality to be specified where the stream will be flushed after * functionality to be specified where the stream will be flushed after
* every line is terminated or newline character is written. * every <code>print</code> or <code>println</code> call, when the
* <code>write</code> methods with array arguments are called, or when a
* single new-line character is written.
* <p> * <p>
* *
* @param out The <code>OutputStream</code> to write to. * @param out The <code>OutputStream</code> to write to.
...@@ -114,7 +116,9 @@ public class PrintStream extends FilterOutputStream ...@@ -114,7 +116,9 @@ public class PrintStream extends FilterOutputStream
* This method intializes a new <code>PrintStream</code> object to write * This method intializes a new <code>PrintStream</code> object to write
* to the specified output sink. This constructor also allows "auto-flush" * to the specified output sink. This constructor also allows "auto-flush"
* functionality to be specified where the stream will be flushed after * functionality to be specified where the stream will be flushed after
* every line is terminated or newline character is written. * every <code>print</code> or <code>println</code> call, when the
* <code>write</code> methods with array arguments are called, or when a
* single new-line character is written.
* <p> * <p>
* *
* @param out The <code>OutputStream</code> to write to. * @param out The <code>OutputStream</code> to write to.
...@@ -256,10 +260,8 @@ public class PrintStream extends FilterOutputStream ...@@ -256,10 +260,8 @@ public class PrintStream extends FilterOutputStream
{ {
pw.print (str); pw.print (str);
if (str != null && auto_flush) if (auto_flush)
if ((str.indexOf ('\r') != -1) flush ();
|| (str.indexOf ('\n') != -1))
flush ();
} }
/** /**
...@@ -422,9 +424,21 @@ public class PrintStream extends FilterOutputStream ...@@ -422,9 +424,21 @@ public class PrintStream extends FilterOutputStream
*/ */
public void write (int oneByte) public void write (int oneByte)
{ {
byte[] data = new byte [1]; // We actually have to implement this method. Flush first so that
data [0] = (byte) (oneByte & 0xff); // things get written in the right order.
write (data, 0, 1); flush();
try
{
out.write (oneByte & 0xff);
if (auto_flush && (oneByte == '\n'))
flush ();
}
catch (IOException e)
{
setError ();
}
} }
/** /**
...@@ -446,19 +460,12 @@ public class PrintStream extends FilterOutputStream ...@@ -446,19 +460,12 @@ public class PrintStream extends FilterOutputStream
out.write (buffer, offset, len); out.write (buffer, offset, len);
if (auto_flush) if (auto_flush)
for (int i = offset; i < len; i++) flush ();
if ((buffer [i] == '\r')
|| (buffer [i] == '\n'))
{
flush ();
break;
}
} }
catch (IOException e) catch (IOException e)
{ {
setError (); setError ();
} }
} }
} // class PrintStream } // class PrintStream
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