aboutsummaryrefslogtreecommitdiff
path: root/libjava/gnu/gcj
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2006-06-27 20:38:10 +0000
committerTom Tromey <tromey@gcc.gnu.org>2006-06-27 20:38:10 +0000
commit9e01bff779fdaf1fb6621fe30f679d6aca0029ec (patch)
tree4559b8284607c63eae3517638fbdf14bec92fafd /libjava/gnu/gcj
parent80cd0e33d9bcc374f71e86eb710d05ac12ff20ab (diff)
downloadgcc-9e01bff779fdaf1fb6621fe30f679d6aca0029ec.zip
gcc-9e01bff779fdaf1fb6621fe30f679d6aca0029ec.tar.gz
gcc-9e01bff779fdaf1fb6621fe30f679d6aca0029ec.tar.bz2
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
Diffstat (limited to 'libjava/gnu/gcj')
-rw-r--r--libjava/gnu/gcj/convert/CharsetToBytesAdaptor.java28
-rw-r--r--libjava/gnu/gcj/convert/UnicodeToBytes.java11
2 files changed, 27 insertions, 12 deletions
diff --git a/libjava/gnu/gcj/convert/CharsetToBytesAdaptor.java b/libjava/gnu/gcj/convert/CharsetToBytesAdaptor.java
index 4e9bcd5..80e749c 100644
--- a/libjava/gnu/gcj/convert/CharsetToBytesAdaptor.java
+++ b/libjava/gnu/gcj/convert/CharsetToBytesAdaptor.java
@@ -39,6 +39,11 @@ public class CharsetToBytesAdaptor extends UnicodeToBytes
private boolean closedEncoder;
/**
+ * True if there are bytes pending in the encoder.
+ */
+ private boolean hasBytes;
+
+ /**
* True if we're finished.
*/
private boolean finished;
@@ -112,20 +117,16 @@ public class CharsetToBytesAdaptor extends UnicodeToBytes
// Set the current position.
outBuf.position(count);
- // If we've already said that there is no more input available,
- // then we simply try to flush again.
+ // Do the conversion.
+ CoderResult result = encoder.encode(inBuf, outBuf, closedEncoder);
+ hasBytes = result == CoderResult.OVERFLOW;
if (closedEncoder)
{
- CoderResult result = encoder.flush(outBuf);
+ result = encoder.flush(outBuf);
if (result == CoderResult.UNDERFLOW)
finished = true;
- }
- else
- {
- // Do the conversion. If there are no characters to write,
- // then we are finished.
- closedEncoder = ! inBuf.hasRemaining();
- encoder.encode(inBuf, outBuf, closedEncoder);
+ else
+ hasBytes = true;
}
// Mark the new end of buf.
@@ -140,7 +141,12 @@ public class CharsetToBytesAdaptor extends UnicodeToBytes
*/
public boolean havePendingBytes()
{
- return ! finished;
+ return hasBytes;
+ }
+
+ public void setFinished()
+ {
+ closedEncoder = true;
}
// These aren't cached.
diff --git a/libjava/gnu/gcj/convert/UnicodeToBytes.java b/libjava/gnu/gcj/convert/UnicodeToBytes.java
index 8522bec..51d6939 100644
--- a/libjava/gnu/gcj/convert/UnicodeToBytes.java
+++ b/libjava/gnu/gcj/convert/UnicodeToBytes.java
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999, 2000, 2001, 2003, 2005 Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001, 2003, 2005, 2006 Free Software Foundation
This file is part of libgcj.
@@ -172,6 +172,15 @@ public abstract class UnicodeToBytes extends IOConverter
return false;
}
+ /**
+ * Users should call this method when the input is coming to an
+ * end. This signals that the next write (which might be
+ * zero-length) ought to flush any internal state.
+ */
+ public void setFinished()
+ {
+ }
+
/** Indicate that the converter is resuable.
* This class keeps track of converters on a per-encoding basis.
* When done with an encoder you may call this method to indicate