Path: blob/master/test/jdk/sun/nio/cs/OLD/MS932_OLD.java
41155 views
/*1* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/242526import java.nio.ByteBuffer;27import java.nio.CharBuffer;28import java.nio.charset.Charset;29import java.nio.charset.CharsetDecoder;30import java.nio.charset.CharsetEncoder;31import java.nio.charset.CoderResult;32import sun.nio.cs.HistoricallyNamedCharset;33import sun.nio.cs.ext.*;3435public class MS932_OLD extends Charset implements HistoricallyNamedCharset36{37public MS932_OLD() {38super("windows-31j-OLD", null);39}4041public String historicalName() {42return "MS932";43}4445public boolean contains(Charset cs) {46return ((cs.name().equals("US-ASCII"))47|| (cs instanceof JIS_X_0201_OLD)48|| (cs instanceof MS932_OLD));49}5051public CharsetDecoder newDecoder() {52return new Decoder(this);53}5455public CharsetEncoder newEncoder() {56return new Encoder(this);57}5859private static class Decoder extends MS932DB.Decoder60// implements DelegatableDecoder61{6263JIS_X_0201_OLD.Decoder jisDec0201;6465private Decoder(Charset cs) {66super(cs);67jisDec0201 = new JIS_X_0201_OLD.Decoder(cs);68}6970protected char decodeSingle(int b) {71// If the high bits are all off, it's ASCII == Unicode72if ((b & 0xFF80) == 0) {73return (char)b;74}75return jisDec0201.decode(b);76}7778// Make some protected methods public for use by JISAutoDetect79public CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) {80return super.decodeLoop(src, dst);81}82public void implReset() {83super.implReset();84}85public CoderResult implFlush(CharBuffer out) {86return super.implFlush(out);87}88}8990private static class Encoder extends MS932DB.Encoder {9192private JIS_X_0201_OLD.Encoder jisEnc0201;939495private Encoder(Charset cs) {96super(cs);97jisEnc0201 = new JIS_X_0201_OLD.Encoder(cs);98}99100protected int encodeSingle(char inputChar) {101102byte b;103// \u0000 - \u007F map straight through104if ((inputChar & 0xFF80) == 0) {105return ((byte)inputChar);106}107108if ((b = jisEnc0201.encode(inputChar)) == 0)109return -1;110else111return b;112}113}114}115116117