Re: UTF8 encoding problems

Øyvind Harboe <[email protected]> Fri, 23 Jan 2004 14:24:25 +0100
Newsgroups gmane.comp.java.classpath.extensions.discuss
Organization Zylin AS
Message-ID <1074864265.16304.19.camel@famine>
fre, 23.01.2004 kl. 13.30 skrev Chris Burdess:
> Øyvind Harboe wrote:
> > I'm running into an UTF8 encoding problem.
> >
> > My test app(attached) works fine w/GNU Classpath and Classpath w/Sun,
> > but causes an exception w/GCJ(attached).
> 
> You should probably take this up with [email protected] if it's specific 
> to natively compiled binaries.

The patch below fixes the problem on my rocket.

The reason Suns JRE and GCJ differs in behaviour, is that buffered output 
streams have differently sized buffers.


Index: RFC2822OutputStream.java
===================================================================
retrieving revision 1.6
diff -u -r1.6 RFC2822OutputStream.java
--- RFC2822OutputStream.java	23 Oct 2003 16:40:09 -0000	1.6
+++ RFC2822OutputStream.java	23 Jan 2004 12:39:38 -0000
@@ -112,7 +112,8 @@
   {
     int d = off;
     len += off;
-    for (int i=off; i<len; i++)
+	int i;
+    for (i=off; i<len; i++)
     {
       count++;
       if (b[i]==CR || b[i]==LF)
@@ -132,8 +133,11 @@
         }
       }
     }
-    if (count>0)
-      out.write(b, d, count);
+	int leftToWrite=i-d;
+    if (leftToWrite>0)
+	{
+      out.write(b, d, leftToWrite);
+	}
   }
 
 }