jdk/src/share/classes/sun/nio/cs/ext/IBM943C.java
changeset 2921 d9d491a5a169
parent 2 90ce3da70b43
child 5506 202f599c92aa
--- a/jdk/src/share/classes/sun/nio/cs/ext/IBM943C.java	Wed May 20 13:55:50 2009 -0700
+++ b/jdk/src/share/classes/sun/nio/cs/ext/IBM943C.java	Thu May 21 23:32:46 2009 -0700
@@ -23,15 +23,12 @@
  * have any questions.
  */
 
-/*
- */
-
 package sun.nio.cs.ext;
 
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CharacterCodingException;
+import java.util.Arrays;
 import sun.nio.cs.HistoricallyNamedCharset;
 
 public class IBM943C extends Charset implements HistoricallyNamedCharset
@@ -51,54 +48,37 @@
     }
 
     public CharsetDecoder newDecoder() {
-        return new Decoder(this);
+        return new DoubleByte.Decoder(this,
+                                      IBM943.b2c,
+                                      b2cSB,
+                                      0x40,
+                                      0xfc);
     }
 
     public CharsetEncoder newEncoder() {
-        return new Encoder(this);
-    }
-
-    private static class Decoder extends IBM943.Decoder {
-        protected static final String singleByteToChar;
-
-        static {
-          String indexs = "";
-          for (char c = '\0'; c < '\u0080'; ++c) indexs += c;
-              singleByteToChar = indexs +
-                                 IBM943.Decoder.singleByteToChar.substring(indexs.length());
-        }
-
-        public Decoder(Charset cs) {
-            super(cs, singleByteToChar);
-        }
+        return new DoubleByte.Encoder(this, c2b, c2bIndex);
     }
 
-    private static class Encoder extends IBM943.Encoder {
-
-        protected static final short index1[];
-        protected static final String index2a;
-        protected static final int shift = 6;
-
-        static {
-            String indexs = "";
-            for (char c = '\0'; c < '\u0080'; ++c) indexs += c;
-                index2a = IBM943.Encoder.index2a + indexs;
+    final static char[] b2cSB;
+    final static char[] c2b;
+    final static char[] c2bIndex;
 
-            int o = IBM943.Encoder.index2a.length() + 15000;
-            index1 = new short[IBM943.Encoder.index1.length];
-            System.arraycopy(IBM943.Encoder.index1,
-                             0,
-                             index1,
-                             0,
-                             IBM943.Encoder.index1.length);
-
-            for (int i = 0; i * (1<<shift) < 128; ++i) {
-                index1[i] = (short)(o + i * (1<<shift));
-            }
+    static {
+        IBM943.initb2c();
+        b2cSB = new char[0x100];
+        for (int i = 0; i < 0x80; i++) {
+            b2cSB[i] = (char)i;
+        }
+        for (int i = 0x80; i < 0x100; i++) {
+            b2cSB[i] = IBM943.b2cSB[i];
         }
 
-        public Encoder(Charset cs) {
-            super(cs, index1, index2a);
+        IBM943.initc2b();
+        c2b = Arrays.copyOf(IBM943.c2b, IBM943.c2b.length);
+        c2bIndex = Arrays.copyOf(IBM943.c2bIndex, IBM943.c2bIndex.length);
+        for (char c = '\0'; c < '\u0080'; ++c) {
+            int index = c2bIndex[c >> 8];
+            c2b[index + (c & 0xff)] = c;
         }
     }
 }