--- old/src/java.base/share/classes/sun/nio/cs/HKSCS.java 2015-10-30 14:03:48.350317076 -0700 +++ new/src/java.base/share/classes/sun/nio/cs/HKSCS.java 2015-10-30 14:03:48.116317962 -0700 @@ -53,7 +53,7 @@ // super(cs, 0.5f, 1.0f); // need to extends DoubleByte.Decoder so the // sun.io can use it. this implementation - super(cs, 0.5f, 1.0f, null, null, 0, 0); + super(cs, 0.5f, 1.0f, null, null, 0, 0, true); this.big5Dec = big5Dec; this.b2cBmp = b2cBmp; this.b2cSupp = b2cSupp; @@ -239,7 +239,7 @@ char[][] c2bBmp, char[][] c2bSupp) { - super(cs, null, null); + super(cs, null, null, true); this.big5Enc = big5Enc; this.c2bBmp = c2bBmp; this.c2bSupp = c2bSupp; @@ -389,6 +389,33 @@ return dp; } + public int encodeFromUTF16(byte[] src, int sp, int len, byte[] dst) { + int dp = 0; + int sl = sp + len; + int dl = dst.length; + while (sp < sl) { + char c = StringUTF16.getChar(src, sp++); + int bb = encodeChar(c); + if (bb == UNMAPPABLE_ENCODING) { + if (!Character.isHighSurrogate(c) || sp == sl || + !Character.isLowSurrogate(StringUTF16.getChar(src,sp)) || + (bb = encodeSupp(Character.toCodePoint(c, StringUTF16.getChar(src, sp++)))) + == UNMAPPABLE_ENCODING) { + dst[dp++] = repl[0]; + if (repl.length > 1) + dst[dp++] = repl[1]; + continue; + } + } + if (bb > MAX_SINGLEBYTE) { // DoubleByte + dst[dp++] = (byte)(bb >> 8); + dst[dp++] = (byte)bb; + } else { // SingleByte + dst[dp++] = (byte)bb; + } + } + return dp; + } static char[] C2B_UNMAPPABLE = new char[0x100]; static {