Commit 60e9f0d7 by Mark Wielaard

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
parent ddc612a2
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.
2003-06-07 Michael Koch <konqueror@gmx.de> 2003-06-07 Michael Koch <konqueror@gmx.de>
* include/posix.h * include/posix.h
......
/* Copyright (C) 1999 Free Software Foundation /* Copyright (C) 1999, 2003 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -22,6 +22,11 @@ public class Output_EUCJIS extends UnicodeToBytes ...@@ -22,6 +22,11 @@ public class Output_EUCJIS extends UnicodeToBytes
public native int write (String str, int inpos, int inlength, char[] work); public native int write (String str, int inpos, int inlength, char[] work);
public boolean havePendingBytes()
{
return pending1 >= 0;
}
int pending1 = -1; int pending1 = -1;
int pending2; int pending2;
} }
/* Copyright (C) 1999 Free Software Foundation /* Copyright (C) 1999, 2003 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -22,5 +22,10 @@ public class Output_SJIS extends UnicodeToBytes ...@@ -22,5 +22,10 @@ public class Output_SJIS extends UnicodeToBytes
public native int write (String str, int inpos, int inlength, char[] work); public native int write (String str, int inpos, int inlength, char[] work);
public boolean havePendingBytes()
{
return pending >= 0;
}
int pending = -1; int pending = -1;
} }
/* Copyright (C) 1999, 2000 Free Software Foundation /* Copyright (C) 1999, 2000, 2003 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -104,6 +104,7 @@ public class Output_UTF8 extends UnicodeToBytes ...@@ -104,6 +104,7 @@ public class Output_UTF8 extends UnicodeToBytes
{ {
value = (hi_part - 0xD800) * 0x400 + (ch - 0xDC00) + 0x10000; value = (hi_part - 0xD800) * 0x400 + (ch - 0xDC00) + 0x10000;
buf[count++] = (byte) (0xF0 | (value >> 18)); buf[count++] = (byte) (0xF0 | (value >> 18));
avail--;
bytes_todo = 3; bytes_todo = 3;
hi_part = 0; hi_part = 0;
} }
...@@ -118,4 +119,10 @@ public class Output_UTF8 extends UnicodeToBytes ...@@ -118,4 +119,10 @@ public class Output_UTF8 extends UnicodeToBytes
} }
return inpos - start_pos; return inpos - start_pos;
} }
public boolean havePendingBytes()
{
return bytes_todo > 0;
}
} }
/* Copyright (C) 1999, 2000, 2001 Free Software Foundation /* Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -146,6 +146,17 @@ public abstract class UnicodeToBytes extends IOConverter ...@@ -146,6 +146,17 @@ public abstract class UnicodeToBytes extends IOConverter
return write(work, 0, srcEnd - inpos); return write(work, 0, srcEnd - inpos);
} }
/**
* Returns true when the converter has consumed some bytes that are
* not yet converted to characters because further continuation
* bytes are needed. Defaults to false, should be overridden by
* decoders that internally store some bytes.
*/
public boolean havePendingBytes()
{
return false;
}
/** Indicate that the converter is resuable. /** Indicate that the converter is resuable.
* This class keeps track of converters on a per-encoding basis. * This class keeps track of converters on a per-encoding basis.
* When done with an encoder you may call this method to indicate * When done with an encoder you may call this method to indicate
......
...@@ -215,7 +215,7 @@ public class OutputStreamWriter extends Writer ...@@ -215,7 +215,7 @@ public class OutputStreamWriter extends Writer
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 || converter.havePendingBytes())
{ {
// We must flush if out.count == out.buf.length. // We must flush if out.count == out.buf.length.
// It is probably a good idea to flush if out.buf is almost full. // It is probably a good idea to flush if out.buf is almost full.
...@@ -228,6 +228,13 @@ public class OutputStreamWriter extends Writer ...@@ -228,6 +228,13 @@ public class OutputStreamWriter extends Writer
} }
converter.setOutput(out.buf, out.count); converter.setOutput(out.buf, out.count);
int converted = converter.write(buf, offset, count); int converted = converter.write(buf, offset, count);
// Flush if we cannot make progress.
if (converted == 0 && out.count == converter.count)
{
out.flush();
if (out.count != 0)
throw new IOException("unable to flush output byte buffer");
}
offset += converted; offset += converted;
count -= converted; count -= converted;
out.count = converter.count; out.count = converter.count;
......
/* PrintStream.java -- OutputStream for printing output /* PrintStream.java -- OutputStream for printing output
Copyright (C) 1998,2003 Free Software Foundation, Inc. Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -262,7 +262,7 @@ public class PrintStream extends FilterOutputStream ...@@ -262,7 +262,7 @@ public class PrintStream extends FilterOutputStream
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 || converter.havePendingBytes())
{ {
converter.setOutput(work_bytes, 0); converter.setOutput(work_bytes, 0);
int converted = converter.write(buf, offset, count); int converted = converter.write(buf, offset, count);
...@@ -275,7 +275,7 @@ public class PrintStream extends FilterOutputStream ...@@ -275,7 +275,7 @@ public class PrintStream extends FilterOutputStream
private void writeChars(String str, int offset, int count) private void writeChars(String str, int offset, int count)
throws IOException throws IOException
{ {
while (count > 0) while (count > 0 || converter.havePendingBytes())
{ {
converter.setOutput(work_bytes, 0); converter.setOutput(work_bytes, 0);
int converted = converter.write(str, offset, count, work); int converted = converter.write(str, offset, count, work);
......
...@@ -602,12 +602,12 @@ java::lang::String::getBytes (jstring enc) ...@@ -602,12 +602,12 @@ java::lang::String::getBytes (jstring enc)
jint offset = 0; jint offset = 0;
gnu::gcj::convert::UnicodeToBytes *converter gnu::gcj::convert::UnicodeToBytes *converter
= gnu::gcj::convert::UnicodeToBytes::getEncoder(enc); = gnu::gcj::convert::UnicodeToBytes::getEncoder(enc);
while (todo > 0) while (todo > 0 || converter->havePendingBytes())
{ {
converter->setOutput(buffer, bufpos); converter->setOutput(buffer, bufpos);
int converted = converter->write(this, offset, todo, NULL); int converted = converter->write(this, offset, todo, NULL);
bufpos = converter->count; bufpos = converter->count;
if (converted == 0) if (converted == 0 && bufpos == converter->count)
{ {
buflen *= 2; buflen *= 2;
jbyteArray newbuffer = JvNewByteArray(buflen); jbyteArray newbuffer = JvNewByteArray(buflen);
...@@ -615,10 +615,10 @@ java::lang::String::getBytes (jstring enc) ...@@ -615,10 +615,10 @@ java::lang::String::getBytes (jstring enc)
buffer = newbuffer; buffer = newbuffer;
} }
else else
{ bufpos = converter->count;
offset += converted;
todo -= converted; offset += converted;
} todo -= converted;
} }
converter->done (); converter->done ();
if (bufpos == buflen) if (bufpos == buflen)
......
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