[kaffe] CVS kaffe (guilhem): Fix for bug #24

Kaffe CVS cvs-commits at kaffe.org
Fri Mar 24 10:11:52 PST 2006


PatchSet 7168 
Date: 2006/03/24 18:03:25
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Fix for bug #24

        * libraries/javalib/external/classpath/java/io/PrintStream.java
        (writeChars): Catch UnsupportedEncodingException if we use the
        default encoding and replace the encoding with a known working
        one.

Members: 
	ChangeLog:1.4686->1.4687 
	libraries/javalib/external/classpath/java/io/PrintStream.java:1.2->1.3 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4686 kaffe/ChangeLog:1.4687
--- kaffe/ChangeLog:1.4686	Fri Mar 24 11:02:52 2006
+++ kaffe/ChangeLog	Fri Mar 24 18:03:25 2006
@@ -1,3 +1,10 @@
+2006-03-24  Guilhem Lavaux  <guilhem at kaffe.org>
+
+	* libraries/javalib/external/classpath/java/io/PrintStream.java
+	(writeChars): Catch UnsupportedEncodingException if we use the
+	default encoding and replace the encoding with a known working
+	one.
+	
 2006-03-24  Dalibor Topic  <robilad at kaffe.org>
 
 	* Makefile.am (EXTRA_DIST): Added FAQ/FAQ.blackfin.
Index: kaffe/libraries/javalib/external/classpath/java/io/PrintStream.java
diff -u kaffe/libraries/javalib/external/classpath/java/io/PrintStream.java:1.2 kaffe/libraries/javalib/external/classpath/java/io/PrintStream.java:1.3
--- kaffe/libraries/javalib/external/classpath/java/io/PrintStream.java:1.2	Fri Jan 13 17:54:24 2006
+++ kaffe/libraries/javalib/external/classpath/java/io/PrintStream.java	Fri Mar 24 18:03:27 2006
@@ -86,6 +86,8 @@
    */
   private boolean auto_flush;
 
+  private boolean defaultEncoding;
+
   /**
    * This method intializes a new <code>PrintStream</code> object to write
    * to the specified output sink.
@@ -124,6 +126,7 @@
 	this.encoding = "ISO8859_1";
     }
     this.auto_flush = auto_flush;
+    this.defaultEncoding = true;
   }
 
   /**
@@ -259,15 +262,43 @@
   private void writeChars(char[] buf, int offset, int count)
     throws IOException
   {
-      byte[] bytes = (new String(buf, offset, count)).getBytes(encoding);
-      out.write(bytes, 0, bytes.length);
+    try
+      {
+	byte[] bytes = (new String(buf, offset, count)).getBytes(encoding);
+	out.write(bytes, 0, bytes.length);
+      }
+    catch (UnsupportedEncodingException e)
+      {
+	if (defaultEncoding)
+	  {
+	    this.encoding = "ISO8859_1";
+	    writeChars(buf, offset, count);
+	  }
+	else
+	  throw e;
+      }
   }
 
   private void writeChars(String str, int offset, int count)
     throws IOException
   {
-      byte[] bytes = str.substring(offset, offset+count).getBytes(encoding);
-      out.write(bytes, 0, bytes.length);
+    try
+      {
+	byte[] bytes = str.substring(offset, offset+count).getBytes(encoding);
+	out.write(bytes, 0, bytes.length);
+      }
+    catch (UnsupportedEncodingException e)
+      {
+	if (defaultEncoding)
+	  {
+	    this.encoding = "ISO8859_1";
+	    writeChars(str, offset, count);
+	  }
+	else
+	  {
+	    throw e;
+	  }
+      }
   }
 
   /**




More information about the kaffe mailing list