src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022_CN_CNS.java

Print this page




  50                 (cs instanceof ISO2022_CN_CNS));
  51     }
  52 
  53     public String historicalName() {
  54         return "ISO2022CN_CNS";
  55     }
  56 
  57     public CharsetDecoder newDecoder() {
  58         return new ISO2022_CN.Decoder(this);
  59     }
  60 
  61     public CharsetEncoder newEncoder() {
  62         return new Encoder(this);
  63     }
  64 
  65     private static class Encoder extends ISO2022.Encoder {
  66 
  67         public Encoder(Charset cs)
  68         {
  69             super(cs);
  70             SODesig = "$)G";
  71             SS2Desig = "$*H";
  72             SS3Desig = "$+I";
  73 
  74             try {
  75                 Charset cset = Charset.forName("EUC_TW"); // CNS11643
  76                 ISOEncoder = cset.newEncoder();
  77             } catch (Exception e) { }
  78         }
  79 
  80         private byte[] bb = new byte[4];
  81         public boolean canEncode(char c) {
  82             int n = 0;
  83             return (c <= '\u007f' ||
  84                     (n = ((EUC_TW.Encoder)ISOEncoder).toEUC(c, bb)) == 2 ||
  85                     (n == 4 && bb[0] == SS2 &&
  86                      (bb[1] == PLANE2 || bb[1] == PLANE3)));
  87         }
  88 
  89         /*
  90          * Since ISO2022-CN-CNS possesses a CharsetEncoder
  91          * without the corresponding CharsetDecoder half the
  92          * default replacement check needs to be overridden


  50                 (cs instanceof ISO2022_CN_CNS));
  51     }
  52 
  53     public String historicalName() {
  54         return "ISO2022CN_CNS";
  55     }
  56 
  57     public CharsetDecoder newDecoder() {
  58         return new ISO2022_CN.Decoder(this);
  59     }
  60 
  61     public CharsetEncoder newEncoder() {
  62         return new Encoder(this);
  63     }
  64 
  65     private static class Encoder extends ISO2022.Encoder {
  66 
  67         public Encoder(Charset cs)
  68         {
  69             super(cs);
  70             SODesig =  new byte[] {'$', ')', 'G' };
  71             SS2Desig = new byte[] {'$', '*', 'H' };
  72             SS3Desig = new byte[] {'$', '+', 'I' };
  73 
  74             try {
  75                 Charset cset = Charset.forName("EUC_TW"); // CNS11643
  76                 ISOEncoder = cset.newEncoder();
  77             } catch (Exception e) { }
  78         }
  79 
  80         private byte[] bb = new byte[4];
  81         public boolean canEncode(char c) {
  82             int n = 0;
  83             return (c <= '\u007f' ||
  84                     (n = ((EUC_TW.Encoder)ISOEncoder).toEUC(c, bb)) == 2 ||
  85                     (n == 4 && bb[0] == SS2 &&
  86                      (bb[1] == PLANE2 || bb[1] == PLANE3)));
  87         }
  88 
  89         /*
  90          * Since ISO2022-CN-CNS possesses a CharsetEncoder
  91          * without the corresponding CharsetDecoder half the
  92          * default replacement check needs to be overridden