28 import java.nio.CharBuffer; 29 import java.nio.charset.Charset; 30 import java.nio.charset.CharsetDecoder; 31 import java.nio.charset.CharsetEncoder; 32 import java.nio.charset.CoderResult; 33 import sun.nio.cs.HistoricallyNamedCharset; 34 import sun.nio.cs.ext.*; 35 36 public class MS932_OLD extends Charset implements HistoricallyNamedCharset 37 { 38 public MS932_OLD() { 39 super("windows-31j-OLD", null); 40 } 41 42 public String historicalName() { 43 return "MS932"; 44 } 45 46 public boolean contains(Charset cs) { 47 return ((cs.name().equals("US-ASCII")) 48 || (cs instanceof JIS_X_0201) 49 || (cs instanceof MS932_OLD)); 50 } 51 52 public CharsetDecoder newDecoder() { 53 return new Decoder(this); 54 } 55 56 public CharsetEncoder newEncoder() { 57 return new Encoder(this); 58 } 59 60 private static class Decoder extends MS932DB.Decoder 61 // implements DelegatableDecoder 62 { 63 64 JIS_X_0201.Decoder jisDec0201; 65 66 private Decoder(Charset cs) { 67 super(cs); 68 jisDec0201 = new JIS_X_0201.Decoder(cs); 69 } 70 71 protected char decodeSingle(int b) { 72 // If the high bits are all off, it's ASCII == Unicode 73 if ((b & 0xFF80) == 0) { 74 return (char)b; 75 } 76 return jisDec0201.decode(b); 77 } 78 79 // Make some protected methods public for use by JISAutoDetect 80 public CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) { 81 return super.decodeLoop(src, dst); 82 } 83 public void implReset() { 84 super.implReset(); 85 } 86 public CoderResult implFlush(CharBuffer out) { 87 return super.implFlush(out); 88 } 89 } 90 91 private static class Encoder extends MS932DB.Encoder { 92 93 private JIS_X_0201.Encoder jisEnc0201; 94 95 96 private Encoder(Charset cs) { 97 super(cs); 98 jisEnc0201 = new JIS_X_0201.Encoder(cs); 99 } 100 101 protected int encodeSingle(char inputChar) { 102 103 byte b; 104 // \u0000 - \u007F map straight through 105 if ((inputChar & 0xFF80) == 0) { 106 return ((byte)inputChar); 107 } 108 109 if ((b = jisEnc0201.encode(inputChar)) == 0) 110 return -1; 111 else 112 return b; 113 } 114 } 115 } | 28 import java.nio.CharBuffer; 29 import java.nio.charset.Charset; 30 import java.nio.charset.CharsetDecoder; 31 import java.nio.charset.CharsetEncoder; 32 import java.nio.charset.CoderResult; 33 import sun.nio.cs.HistoricallyNamedCharset; 34 import sun.nio.cs.ext.*; 35 36 public class MS932_OLD extends Charset implements HistoricallyNamedCharset 37 { 38 public MS932_OLD() { 39 super("windows-31j-OLD", null); 40 } 41 42 public String historicalName() { 43 return "MS932"; 44 } 45 46 public boolean contains(Charset cs) { 47 return ((cs.name().equals("US-ASCII")) 48 || (cs instanceof JIS_X_0201_OLD) 49 || (cs instanceof MS932_OLD)); 50 } 51 52 public CharsetDecoder newDecoder() { 53 return new Decoder(this); 54 } 55 56 public CharsetEncoder newEncoder() { 57 return new Encoder(this); 58 } 59 60 private static class Decoder extends MS932DB.Decoder 61 // implements DelegatableDecoder 62 { 63 64 JIS_X_0201_OLD.Decoder jisDec0201; 65 66 private Decoder(Charset cs) { 67 super(cs); 68 jisDec0201 = new JIS_X_0201_OLD.Decoder(cs); 69 } 70 71 protected char decodeSingle(int b) { 72 // If the high bits are all off, it's ASCII == Unicode 73 if ((b & 0xFF80) == 0) { 74 return (char)b; 75 } 76 return jisDec0201.decode(b); 77 } 78 79 // Make some protected methods public for use by JISAutoDetect 80 public CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) { 81 return super.decodeLoop(src, dst); 82 } 83 public void implReset() { 84 super.implReset(); 85 } 86 public CoderResult implFlush(CharBuffer out) { 87 return super.implFlush(out); 88 } 89 } 90 91 private static class Encoder extends MS932DB.Encoder { 92 93 private JIS_X_0201_OLD.Encoder jisEnc0201; 94 95 96 private Encoder(Charset cs) { 97 super(cs); 98 jisEnc0201 = new JIS_X_0201_OLD.Encoder(cs); 99 } 100 101 protected int encodeSingle(char inputChar) { 102 103 byte b; 104 // \u0000 - \u007F map straight through 105 if ((inputChar & 0xFF80) == 0) { 106 return ((byte)inputChar); 107 } 108 109 if ((b = jisEnc0201.encode(inputChar)) == 0) 110 return -1; 111 else 112 return b; 113 } 114 } 115 } |