--- old/src/java.desktop/unix/classes/sun/awt/motif/X11JIS0201.java 2015-02-19 16:13:12.549548380 -0800 +++ new/src/java.desktop/unix/classes/sun/awt/motif/X11JIS0201.java 2015-02-19 16:13:12.433548383 -0800 @@ -28,15 +28,21 @@ import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.*; -import sun.nio.cs.*; -import sun.nio.cs.ext.JIS_X_0201; -import static sun.nio.cs.CharsetMapping.*; +import static sun.awt.motif.DoubleByte.*; public class X11JIS0201 extends Charset { - private static Charset jis0201 = new JIS_X_0201(); - private static SingleByte.Encoder enc = - (SingleByte.Encoder)jis0201.newEncoder(); + private static Charset jis0201 = null; + private static CharsetEncoder enc = null; + + static { + jis0201 = Charset.forName("JIS_X0201"); + if (jis0201 != null) { + enc = jis0201.newEncoder(); + enc.onMalformedInput(CodingErrorAction.REPORT); + enc.onUnmappableCharacter(CodingErrorAction.REPORT); + } + } public X11JIS0201 () { super("X11JIS0201", null); @@ -69,8 +75,13 @@ return false; } - private Surrogate.Parser sgp; + private SurrogateParser sgp; protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) { + + CoderResult cr = CoderResult.UNDERFLOW; + if (enc == null) { /* essentially bail */ + return cr; + } char[] sa = src.array(); int sp = src.arrayOffset() + src.position(); int sl = src.arrayOffset() + src.limit(); @@ -78,26 +89,40 @@ byte[] da = dst.array(); int dp = dst.arrayOffset() + dst.position(); int dl = dst.arrayOffset() + dst.limit(); - CoderResult cr = CoderResult.UNDERFLOW; if ((dl - dp) < (sl - sp)) { sl = sp + (dl - dp); cr = CoderResult.OVERFLOW; } try { + char[] buf = new char[1]; while (sp < sl) { + boolean mapped = false; char c = sa[sp]; - int b = enc.encode(c); - if (b == UNMAPPABLE_ENCODING) { + ByteBuffer bb = null; + /* CharsetEncoders may not be thread safe */ + synchronized (enc) { + if (enc.canEncode(c)) { + buf[0] = c; + CharBuffer cb = CharBuffer.wrap(buf); + try { + bb = enc.encode(cb); + mapped = true; + } catch (CharacterCodingException cce) { + } + } + } + if (mapped && bb != null) { + da[dp++] = bb.get(); + sp++; + } else { if (Character.isSurrogate(c)) { if (sgp == null) - sgp = new Surrogate.Parser(); + sgp = new SurrogateParser(); if (sgp.parse(c, sa, sp, sl) >= 0) return CoderResult.unmappableForLength(2); } return CoderResult.unmappableForLength(1); } - da[dp++] = (byte)b; - sp++; } return cr; } finally { @@ -107,3 +132,4 @@ } } } +