1 /*
   2  * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Sun designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Sun in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 /*
  27  */
  28 
  29 import java.nio.charset.Charset;
  30 import java.nio.charset.CharsetDecoder;
  31 import java.nio.charset.CharsetEncoder;
  32 import java.nio.charset.CharacterCodingException;
  33 import sun.nio.cs.HistoricallyNamedCharset;
  34 
  35 public class IBM942C_OLD extends Charset implements HistoricallyNamedCharset
  36 {
  37 
  38     public IBM942C_OLD() {
  39         super("x-IBM942C_OLD", null);
  40     }
  41 
  42     public String historicalName() {
  43         return "Cp942C";
  44     }
  45 
  46     public boolean contains(Charset cs) {
  47         return ((cs.name().equals("US-ASCII"))
  48                 || (cs instanceof IBM942C_OLD));
  49     }
  50 
  51     public CharsetDecoder newDecoder() {
  52         return new Decoder(this);
  53     }
  54 
  55     public CharsetEncoder newEncoder() {
  56         return new Encoder(this);
  57     }
  58 
  59     private static class Decoder extends IBM942_OLD.Decoder {
  60         protected static final String singleByteToChar;
  61 
  62         static {
  63           String indexs = "";
  64           for (char c = '\0'; c < '\u0080'; ++c) indexs += c;
  65               singleByteToChar = indexs +
  66                                  IBM942_OLD.Decoder.singleByteToChar.substring(indexs.length());
  67         }
  68 
  69         public Decoder(Charset cs) {
  70             super(cs, singleByteToChar);
  71         }
  72     }
  73 
  74     private static class Encoder extends IBM942_OLD.Encoder {
  75 
  76    protected static final short index1[];
  77    protected static final String index2a;
  78    protected static final int shift = 5;
  79 
  80         static {
  81 
  82             String indexs = "";
  83             for (char c = '\0'; c < '\u0080'; ++c) indexs += c;
  84                 index2a = IBM942_OLD.Encoder.index2a + indexs;
  85             int o = IBM942_OLD.Encoder.index2a.length() + 15000;
  86             index1 = new short[IBM942_OLD.Encoder.index1.length];
  87 
  88 
  89             System.arraycopy(IBM942_OLD.Encoder.index1,
  90                              0,
  91                              index1,
  92                              0,
  93                              IBM942_OLD.Encoder.index1.length);
  94 
  95             for (int i = 0; i * (1<<shift) < 128; ++i) {
  96                 index1[i] = (short)(o + i * (1<<shift));
  97             }
  98         }
  99 
 100         public Encoder(Charset cs) {
 101             super(cs, index1, index2a);
 102         }
 103     }
 104 }