re PR libgcj/8738 (java.io.CharArrayWriter's write methods erroneously throw IOExceptions)

2002-06-06  James Clark  <jjc@jclark.com>

       Fix for PR libgcj/8738:
       * gnu/gcj/convert/UnicodeToBytes.java (havePendingBytes): New method.
       * gnu/gcj/convert/Output_SJIS.java (havePendingBytes): Likewise.
       * gnu/gcj/convert/Output_EUCJIS.java (havePendingBytes): Likewise.
       * gnu/gcj/convert/Output_UTF8.java (havePendingBytes): Likewise.
       (write): Always decrease avail when count is increased.
       * java/lang/natString.cc (getBytes): Check converter havePendingBytes()
       and whether output buffer is full before increasing size.

2002-06-06  Mark Wielaard  <mark@klomp dot org>

       * java/io/PrintStream.java (writeChars(char[],int, int)):
       Check converter.havePendingBytes().
       (writeChars(String,int,int)): Likewise.
       * java/io/OutputStreamWriter.java (writeChars(char[], int, int)):
       Check converter.havePendingBytes() and flush buffer when stalled.

From-SVN: r67595
This commit is contained in:
Mark Wielaard 2003-06-07 18:35:00 +00:00
parent ddc612a2ba
commit 60e9f0d726
8 changed files with 68 additions and 14 deletions

View file

@ -602,12 +602,12 @@ java::lang::String::getBytes (jstring enc)
jint offset = 0;
gnu::gcj::convert::UnicodeToBytes *converter
= gnu::gcj::convert::UnicodeToBytes::getEncoder(enc);
while (todo > 0)
while (todo > 0 || converter->havePendingBytes())
{
converter->setOutput(buffer, bufpos);
int converted = converter->write(this, offset, todo, NULL);
bufpos = converter->count;
if (converted == 0)
if (converted == 0 && bufpos == converter->count)
{
buflen *= 2;
jbyteArray newbuffer = JvNewByteArray(buflen);
@ -615,10 +615,10 @@ java::lang::String::getBytes (jstring enc)
buffer = newbuffer;
}
else
{
offset += converted;
todo -= converted;
}
bufpos = converter->count;
offset += converted;
todo -= converted;
}
converter->done ();
if (bufpos == buflen)