--- /home/cpdev/src/classpath/java/io/PrintStream.java	2005-07-02 21:03:30.000000000 +0000
+++ java/io/PrintStream.java	2005-06-30 05:34:35.000000000 +0000
@@ -38,6 +38,8 @@
 
 package java.io;
 
+import gnu.gcj.convert.UnicodeToBytes;
+
 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
  * "The Java Language Specification", ISBN 0-201-63451-1
  * Status:  Believed complete and correct to 1.3
@@ -65,11 +67,13 @@
   // Line separator string.
   private static final char[] line_separator
     = System.getProperty("line.separator").toCharArray();
+  
+  UnicodeToBytes converter;
 
-  /**
-   *  Encoding name
-   */
-  private String encoding;
+  // Work buffer of characters for converter.
+  char[] work = new char[100];
+  // Work buffer of bytes where we temporarily keep converter output.
+  byte[] work_bytes = new byte[100];
 
   /**
    * This boolean indicates whether or not an error has ever occurred
@@ -111,15 +115,7 @@
   {
     super (out);
 
-    try {
-	this.encoding = System.getProperty("file.encoding");
-    } catch (SecurityException e){
-	this.encoding = "ISO8859_1";
-    } catch (IllegalArgumentException e){
-	this.encoding = "ISO8859_1";
-    } catch (NullPointerException e){
-	this.encoding = "ISO8859_1";
-    }
+    converter = UnicodeToBytes.getDefaultEncoder();
     this.auto_flush = auto_flush;
   }
 
@@ -143,8 +139,7 @@
   {
     super (out);
 
-    new String(new byte[]{0}, encoding);    // check if encoding is supported
-    this.encoding = encoding;
+    converter = UnicodeToBytes.getEncoder (encoding);
     this.auto_flush = auto_flush;
   }
 
@@ -256,15 +251,27 @@
   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);
+    while (count > 0 || converter.havePendingBytes())
+      {
+	converter.setOutput(work_bytes, 0);
+	int converted = converter.write(buf, offset, count);
+	offset += converted;
+	count -= converted;
+	out.write(work_bytes, 0, converter.count);
+      }
   }
 
   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);
+    while (count > 0 || converter.havePendingBytes())
+      {
+	converter.setOutput(work_bytes, 0);
+	int converted = converter.write(str, offset, count, work);
+	offset += converted;
+	count -= converted;
+	out.write(work_bytes, 0, converter.count);
+      }
   }
 
   /**
@@ -354,7 +361,8 @@
    */
   public synchronized void print (char ch)
   {
-    print(new char[]{ch}, 0, 1, false);
+    work[0] = ch;
+    print(work, 0, 1, false);
   }
 
   /**
@@ -481,7 +489,8 @@
    */
   public synchronized void println (char ch)
   {
-    print(new char[]{ch}, 0, 1, true);
+    work[0] = ch;
+    print(work, 0, 1, true);
   }
 
   /**
