59 60 public CharsetEncoder newEncoder() { 61 return new Encoder(this); 62 } 63 64 private static class Encoder extends ISO2022.Encoder { 65 66 public Encoder(Charset cs) 67 { 68 super(cs); 69 SODesig = "$)G"; 70 SS2Desig = "$*H"; 71 SS3Desig = "$+I"; 72 73 try { 74 Charset cset = Charset.forName("EUC_TW"); // CNS11643 75 ISOEncoder = cset.newEncoder(); 76 } catch (Exception e) { } 77 } 78 79 /* 80 * Since ISO2022-CN-CNS possesses a CharsetEncoder 81 * without the corresponding CharsetDecoder half the 82 * default replacement check needs to be overridden 83 * since the parent class version attempts to 84 * decode 0x3f (?). 85 */ 86 87 public boolean isLegalReplacement(byte[] repl) { 88 // 0x3f is OK as the replacement byte 89 return (repl.length == 1 && repl[0] == (byte) 0x3f); 90 } 91 } 92 } | 59 60 public CharsetEncoder newEncoder() { 61 return new Encoder(this); 62 } 63 64 private static class Encoder extends ISO2022.Encoder { 65 66 public Encoder(Charset cs) 67 { 68 super(cs); 69 SODesig = "$)G"; 70 SS2Desig = "$*H"; 71 SS3Desig = "$+I"; 72 73 try { 74 Charset cset = Charset.forName("EUC_TW"); // CNS11643 75 ISOEncoder = cset.newEncoder(); 76 } catch (Exception e) { } 77 } 78 79 private byte[] bb = new byte[4]; 80 public boolean canEncode(char c) { 81 int n = 0; 82 return (c <= '\u007f' || 83 (n = ((EUC_TW.Encoder)ISOEncoder).toEUC(c, bb)) == 2 || 84 (n == 4 && bb[0] == SS2 && 85 (bb[1] == PLANE2 || bb[1] == PLANE3))); 86 } 87 88 /* 89 * Since ISO2022-CN-CNS possesses a CharsetEncoder 90 * without the corresponding CharsetDecoder half the 91 * default replacement check needs to be overridden 92 * since the parent class version attempts to 93 * decode 0x3f (?). 94 */ 95 96 public boolean isLegalReplacement(byte[] repl) { 97 // 0x3f is OK as the replacement byte 98 return (repl.length == 1 && repl[0] == (byte) 0x3f); 99 } 100 } 101 } |