8080803: sun/nio/cs/FindEncoderBugs.java failing intermittently
Summary: to eliminate an extra byte buffer and copy in iso2022 encoding
Reviewed-by: alanb, darcy
--- a/jdk/src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022.java Fri May 22 08:56:33 2015 -0700
+++ b/jdk/src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022.java Fri May 22 10:33:27 2015 -0700
@@ -395,7 +395,7 @@
protected final byte maximumDesignatorLength = 4;
- protected String SODesig,
+ protected byte[] SODesig,
SS2Desig = null,
SS3Desig = null;
@@ -426,21 +426,18 @@
SS3DesDefined = false;
}
- private int unicodeToNative(char unicode, byte ebyte[])
- {
+ private int unicodeToNative(char unicode, byte ebyte[]) {
int index = 0;
- byte tmpByte[];
char convChar[] = {unicode};
byte convByte[] = new byte[4];
int converted;
try{
CharBuffer cc = CharBuffer.wrap(convChar);
- ByteBuffer bb = ByteBuffer.allocate(4);
+ ByteBuffer bb = ByteBuffer.wrap(convByte);
ISOEncoder.encode(cc, bb, true);
bb.flip();
converted = bb.remaining();
- bb.get(convByte,0,converted);
} catch(Exception e) {
return -1;
}
@@ -449,9 +446,8 @@
if (!SODesDefined) {
newSODesDefined = true;
ebyte[0] = ISO_ESC;
- tmpByte = SODesig.getBytes();
- System.arraycopy(tmpByte,0,ebyte,1,tmpByte.length);
- index = tmpByte.length+1;
+ System.arraycopy(SODesig, 0, ebyte, 1, SODesig.length);
+ index = SODesig.length + 1;
}
if (!shiftout) {
newshiftout = true;
@@ -465,9 +461,8 @@
if (!SS2DesDefined) {
newSS2DesDefined = true;
ebyte[0] = ISO_ESC;
- tmpByte = SS2Desig.getBytes();
- System.arraycopy(tmpByte, 0, ebyte, 1, tmpByte.length);
- index = tmpByte.length+1;
+ System.arraycopy(SS2Desig, 0, ebyte, 1, SS2Desig.length);
+ index = SS2Desig.length + 1;
}
ebyte[index++] = ISO_ESC;
ebyte[index++] = ISO_SS2_7;
@@ -477,9 +472,8 @@
if(!SS3DesDefined){
newSS3DesDefined = true;
ebyte[0] = ISO_ESC;
- tmpByte = SS3Desig.getBytes();
- System.arraycopy(tmpByte, 0, ebyte, 1, tmpByte.length);
- index = tmpByte.length+1;
+ System.arraycopy(SS3Desig, 0, ebyte, 1, SS3Desig.length);
+ index = SS3Desig.length + 1;
}
ebyte[index++] = ISO_ESC;
ebyte[index++] = ISO_SS3_7;
@@ -560,7 +554,6 @@
}
}
-
private CoderResult encodeBufferLoop(CharBuffer src,
ByteBuffer dst)
{
--- a/jdk/src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022_CN_CNS.java Fri May 22 08:56:33 2015 -0700
+++ b/jdk/src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022_CN_CNS.java Fri May 22 10:33:27 2015 -0700
@@ -67,9 +67,9 @@
public Encoder(Charset cs)
{
super(cs);
- SODesig = "$)G";
- SS2Desig = "$*H";
- SS3Desig = "$+I";
+ SODesig = new byte[] {'$', ')', 'G' };
+ SS2Desig = new byte[] {'$', '*', 'H' };
+ SS3Desig = new byte[] {'$', '+', 'I' };
try {
Charset cset = Charset.forName("EUC_TW"); // CNS11643
--- a/jdk/src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022_CN_GB.java Fri May 22 08:56:33 2015 -0700
+++ b/jdk/src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022_CN_GB.java Fri May 22 10:33:27 2015 -0700
@@ -68,7 +68,7 @@
public Encoder(Charset cs)
{
super(cs);
- SODesig = "$)A";
+ SODesig = new byte[] { '$', ')', 'A'};
try {
Charset cset = Charset.forName("EUC_CN"); // GB2312
--- a/jdk/src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022_KR.java Fri May 22 08:56:33 2015 -0700
+++ b/jdk/src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022_KR.java Fri May 22 10:33:27 2015 -0700
@@ -81,11 +81,9 @@
private static class Encoder extends ISO2022.Encoder {
- public Encoder(Charset cs)
- {
+ public Encoder(Charset cs) {
super(cs);
- SODesig = "$)C";
-
+ SODesig = new byte[] {'$', ')', 'C' };
try {
ISOEncoder = ksc5601_cs.newEncoder();
} catch (Exception e) { }