8080803: sun/nio/cs/FindEncoderBugs.java failing intermittently

To eliminate an extra byte buffer and copy in iso2022 encoding

Reviewed-by: alanb, darcy
This commit is contained in:
Xueming Shen 2015-05-22 10:33:27 -07:00
parent d1d75812b0
commit 4612edcf52
4 changed files with 15 additions and 24 deletions

View File

@ -395,7 +395,7 @@ abstract class ISO2022
protected final byte maximumDesignatorLength = 4; protected final byte maximumDesignatorLength = 4;
protected String SODesig, protected byte[] SODesig,
SS2Desig = null, SS2Desig = null,
SS3Desig = null; SS3Desig = null;
@ -426,21 +426,18 @@ abstract class ISO2022
SS3DesDefined = false; SS3DesDefined = false;
} }
private int unicodeToNative(char unicode, byte ebyte[]) private int unicodeToNative(char unicode, byte ebyte[]) {
{
int index = 0; int index = 0;
byte tmpByte[];
char convChar[] = {unicode}; char convChar[] = {unicode};
byte convByte[] = new byte[4]; byte convByte[] = new byte[4];
int converted; int converted;
try{ try{
CharBuffer cc = CharBuffer.wrap(convChar); CharBuffer cc = CharBuffer.wrap(convChar);
ByteBuffer bb = ByteBuffer.allocate(4); ByteBuffer bb = ByteBuffer.wrap(convByte);
ISOEncoder.encode(cc, bb, true); ISOEncoder.encode(cc, bb, true);
bb.flip(); bb.flip();
converted = bb.remaining(); converted = bb.remaining();
bb.get(convByte,0,converted);
} catch(Exception e) { } catch(Exception e) {
return -1; return -1;
} }
@ -449,9 +446,8 @@ abstract class ISO2022
if (!SODesDefined) { if (!SODesDefined) {
newSODesDefined = true; newSODesDefined = true;
ebyte[0] = ISO_ESC; ebyte[0] = ISO_ESC;
tmpByte = SODesig.getBytes(); System.arraycopy(SODesig, 0, ebyte, 1, SODesig.length);
System.arraycopy(tmpByte,0,ebyte,1,tmpByte.length); index = SODesig.length + 1;
index = tmpByte.length+1;
} }
if (!shiftout) { if (!shiftout) {
newshiftout = true; newshiftout = true;
@ -465,9 +461,8 @@ abstract class ISO2022
if (!SS2DesDefined) { if (!SS2DesDefined) {
newSS2DesDefined = true; newSS2DesDefined = true;
ebyte[0] = ISO_ESC; ebyte[0] = ISO_ESC;
tmpByte = SS2Desig.getBytes(); System.arraycopy(SS2Desig, 0, ebyte, 1, SS2Desig.length);
System.arraycopy(tmpByte, 0, ebyte, 1, tmpByte.length); index = SS2Desig.length + 1;
index = tmpByte.length+1;
} }
ebyte[index++] = ISO_ESC; ebyte[index++] = ISO_ESC;
ebyte[index++] = ISO_SS2_7; ebyte[index++] = ISO_SS2_7;
@ -477,9 +472,8 @@ abstract class ISO2022
if(!SS3DesDefined){ if(!SS3DesDefined){
newSS3DesDefined = true; newSS3DesDefined = true;
ebyte[0] = ISO_ESC; ebyte[0] = ISO_ESC;
tmpByte = SS3Desig.getBytes(); System.arraycopy(SS3Desig, 0, ebyte, 1, SS3Desig.length);
System.arraycopy(tmpByte, 0, ebyte, 1, tmpByte.length); index = SS3Desig.length + 1;
index = tmpByte.length+1;
} }
ebyte[index++] = ISO_ESC; ebyte[index++] = ISO_ESC;
ebyte[index++] = ISO_SS3_7; ebyte[index++] = ISO_SS3_7;
@ -560,7 +554,6 @@ abstract class ISO2022
} }
} }
private CoderResult encodeBufferLoop(CharBuffer src, private CoderResult encodeBufferLoop(CharBuffer src,
ByteBuffer dst) ByteBuffer dst)
{ {

View File

@ -67,9 +67,9 @@ public class ISO2022_CN_CNS extends ISO2022 implements HistoricallyNamedCharset
public Encoder(Charset cs) public Encoder(Charset cs)
{ {
super(cs); super(cs);
SODesig = "$)G"; SODesig = new byte[] {'$', ')', 'G' };
SS2Desig = "$*H"; SS2Desig = new byte[] {'$', '*', 'H' };
SS3Desig = "$+I"; SS3Desig = new byte[] {'$', '+', 'I' };
try { try {
Charset cset = Charset.forName("EUC_TW"); // CNS11643 Charset cset = Charset.forName("EUC_TW"); // CNS11643

View File

@ -68,7 +68,7 @@ public class ISO2022_CN_GB extends ISO2022 implements HistoricallyNamedCharset
public Encoder(Charset cs) public Encoder(Charset cs)
{ {
super(cs); super(cs);
SODesig = "$)A"; SODesig = new byte[] { '$', ')', 'A'};
try { try {
Charset cset = Charset.forName("EUC_CN"); // GB2312 Charset cset = Charset.forName("EUC_CN"); // GB2312

View File

@ -81,11 +81,9 @@ implements HistoricallyNamedCharset
private static class Encoder extends ISO2022.Encoder { private static class Encoder extends ISO2022.Encoder {
public Encoder(Charset cs) public Encoder(Charset cs) {
{
super(cs); super(cs);
SODesig = "$)C"; SODesig = new byte[] {'$', ')', 'C' };
try { try {
ISOEncoder = ksc5601_cs.newEncoder(); ISOEncoder = ksc5601_cs.newEncoder();
} catch (Exception e) { } } catch (Exception e) { }