1306N/A/*
2362N/A * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
1306N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1306N/A *
1306N/A * This code is free software; you can redistribute it and/or modify it
1306N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
1306N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
1306N/A *
1306N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1306N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1306N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1306N/A * version 2 for more details (a copy is included in the LICENSE file that
1306N/A * accompanied this code).
1306N/A *
1306N/A * You should have received a copy of the GNU General Public License version
1306N/A * 2 along with this work; if not, write to the Free Software Foundation,
1306N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1306N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1306N/A */
1306N/A
1306N/Aimport java.nio.CharBuffer;
1306N/Aimport java.nio.ByteBuffer;
1306N/Aimport java.nio.charset.*;
1306N/Aimport sun.nio.cs.ext.EUC_KR;
1306N/A
1306N/Apublic class X11KSC5601_OLD extends Charset {
1306N/A public X11KSC5601_OLD () {
1306N/A super("X11KSC5601-OLD", null);
1306N/A }
1306N/A public CharsetEncoder newEncoder() {
1306N/A return new Encoder(this);
1306N/A }
1306N/A public CharsetDecoder newDecoder() {
1306N/A return new Decoder(this);
1306N/A }
1306N/A
1306N/A public boolean contains(Charset cs) {
1306N/A return cs instanceof X11KSC5601_OLD;
1306N/A }
1306N/A
1306N/A private class Encoder extends EUC_KR_OLD.Encoder {
1306N/A public Encoder(Charset cs) {
1306N/A super(cs);
1306N/A }
1306N/A
1306N/A public boolean canEncode(char c) {
1306N/A if (c <= 0x7F) {
1306N/A return false;
1306N/A }
1306N/A return super.canEncode(c);
1306N/A }
1306N/A
1306N/A protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
1306N/A char[] sa = src.array();
1306N/A int sp = src.arrayOffset() + src.position();
1306N/A int sl = src.arrayOffset() + src.limit();
1306N/A byte[] da = dst.array();
1306N/A int dp = dst.arrayOffset() + dst.position();
1306N/A int dl = dst.arrayOffset() + dst.limit();
1306N/A
1306N/A try {
1306N/A while (sp < sl) {
1306N/A char c = sa[sp];
1306N/A if (c <= '\u007f')
1306N/A return CoderResult.unmappableForLength(1);
1306N/A int ncode = encodeDouble(c);
1306N/A if (ncode != 0 && c != '\u0000' ) {
1306N/A da[dp++] = (byte) ((ncode >> 8) & 0x7f);
1306N/A da[dp++] = (byte) (ncode & 0x7f);
1306N/A sp++;
1306N/A continue;
1306N/A }
1306N/A return CoderResult.unmappableForLength(1);
1306N/A }
1306N/A return CoderResult.UNDERFLOW;
1306N/A } finally {
1306N/A src.position(sp - src.arrayOffset());
1306N/A dst.position(dp - dst.arrayOffset());
1306N/A }
1306N/A }
1306N/A public boolean isLegalReplacement(byte[] repl) {
1306N/A return true;
1306N/A }
1306N/A }
1306N/A
1306N/A private class Decoder extends EUC_KR_OLD.Decoder {
1306N/A public Decoder(Charset cs) {
1306N/A super(cs);
1306N/A }
1306N/A
1306N/A protected CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) {
1306N/A byte[] sa = src.array();
1306N/A int sp = src.arrayOffset() + src.position();
1306N/A int sl = src.arrayOffset() + src.limit();
1306N/A assert (sp <= sl);
1306N/A sp = (sp <= sl ? sp : sl);
1306N/A char[] da = dst.array();
1306N/A int dp = dst.arrayOffset() + dst.position();
1306N/A int dl = dst.arrayOffset() + dst.limit();
1306N/A assert (dp <= dl);
1306N/A dp = (dp <= dl ? dp : dl);
1306N/A
1306N/A
1306N/A try {
1306N/A while (sp < sl) {
1306N/A if ( sl - sp < 2) {
1306N/A return CoderResult.UNDERFLOW;
1306N/A }
1306N/A int b1 = sa[sp] & 0xFF | 0x80;
1306N/A int b2 = sa[sp + 1] & 0xFF | 0x80;
1306N/A char c = decodeDouble(b1, b2);
1306N/A if (c == replacement().charAt(0)) {
1306N/A return CoderResult.unmappableForLength(2);
1306N/A }
1306N/A if (dl - dp < 1)
1306N/A return CoderResult.OVERFLOW;
1306N/A da[dp++] = c;
1306N/A sp +=2;
1306N/A }
1306N/A return CoderResult.UNDERFLOW;
1306N/A } finally {
1306N/A src.position(sp - src.arrayOffset());
1306N/A dst.position(dp - dst.arrayOffset());
1306N/A }
1306N/A
1306N/A }
1306N/A }
1306N/A}