From 9e01bff779fdaf1fb6621fe30f679d6aca0029ec Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 27 Jun 2006 20:38:10 +0000 Subject: OutputStreamWriter.java (writeChars): Use a 'do' loop. * java/io/OutputStreamWriter.java (writeChars): Use a 'do' loop. Set 'out.count' earlier. (close): Call setFinished on converter. (flush): Always write work buffer. * java/io/PrintStream.java (writeChars): Do 'do' loop. (close): Call setFinished on converter. Write a 'flush' array. * java/lang/natString.cc (getBytes): Call setFinished on converter. * gnu/gcj/convert/CharsetToBytesAdaptor.java (hasBytes): New field. (write): Set hasBytes. Changed 'finished' logic. (havePendingBytes): Rewrote. (setFinished): New method. * gnu/gcj/convert/UnicodeToBytes.java (setFinished): New method. * testsuite/libjava.lang/RH194522.java: New file. * testsuite/libjava.lang/RH194522.out: New file. From-SVN: r115039 --- libjava/java/io/OutputStreamWriter.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'libjava/java/io/OutputStreamWriter.java') diff --git a/libjava/java/io/OutputStreamWriter.java b/libjava/java/io/OutputStreamWriter.java index 90ecd9f0bc3..1f1666fe11a 100644 --- a/libjava/java/io/OutputStreamWriter.java +++ b/libjava/java/io/OutputStreamWriter.java @@ -1,5 +1,5 @@ /* OutputStreamWriter.java -- Writer that converts chars to bytes - Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -168,6 +168,7 @@ public class OutputStreamWriter extends Writer { if (out != null) { + converter.setFinished(); flush(); out.close(); out = null; @@ -200,11 +201,11 @@ public class OutputStreamWriter extends Writer if (out == null) throw new IOException("Stream closed"); - if (wcount > 0) - { - writeChars(work, 0, wcount); - wcount = 0; - } + // Always write -- if we are close()ing then we want to make + // sure the converter is flushed. + writeChars(work, 0, wcount); + wcount = 0; + out.flush(); } } @@ -243,7 +244,7 @@ public class OutputStreamWriter extends Writer private void writeChars(char[] buf, int offset, int count) throws IOException { - while (count > 0 || converter.havePendingBytes()) + do { // We must flush if out.count == out.buf.length. // It is probably a good idea to flush if out.buf is almost full. @@ -256,6 +257,9 @@ public class OutputStreamWriter extends Writer } converter.setOutput(out.buf, out.count); int converted = converter.write(buf, offset, count); + // Must set this before we flush the output stream, because + // flushing will reset 'out.count'. + out.count = converter.count; // Flush if we cannot make progress. if (converted == 0 && out.count == converter.count) { @@ -265,8 +269,8 @@ public class OutputStreamWriter extends Writer } offset += converted; count -= converted; - out.count = converter.count; } + while (count > 0 || converter.havePendingBytes()); } /** -- cgit v1.2.3