jdk/src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022.java
changeset 30787 758feb62a4b0
parent 25859 3317bb8137f4
equal deleted inserted replaced
30786:fb0d6aaea1dc 30787:758feb62a4b0
   393         public static final byte PLANE3 = (byte)0xA3;
   393         public static final byte PLANE3 = (byte)0xA3;
   394         private final byte MSB = (byte)0x80;
   394         private final byte MSB = (byte)0x80;
   395 
   395 
   396         protected final byte maximumDesignatorLength = 4;
   396         protected final byte maximumDesignatorLength = 4;
   397 
   397 
   398         protected String SODesig,
   398         protected byte[] SODesig,
   399                          SS2Desig = null,
   399                          SS2Desig = null,
   400                          SS3Desig = null;
   400                          SS3Desig = null;
   401 
   401 
   402         protected CharsetEncoder ISOEncoder;
   402         protected CharsetEncoder ISOEncoder;
   403 
   403 
   424             SODesDefined = false;
   424             SODesDefined = false;
   425             SS2DesDefined = false;
   425             SS2DesDefined = false;
   426             SS3DesDefined = false;
   426             SS3DesDefined = false;
   427         }
   427         }
   428 
   428 
   429         private int unicodeToNative(char unicode, byte ebyte[])
   429         private int unicodeToNative(char unicode, byte ebyte[]) {
   430         {
       
   431             int index = 0;
   430             int index = 0;
   432             byte        tmpByte[];
       
   433             char        convChar[] = {unicode};
   431             char        convChar[] = {unicode};
   434             byte        convByte[] = new byte[4];
   432             byte        convByte[] = new byte[4];
   435             int         converted;
   433             int         converted;
   436 
   434 
   437             try{
   435             try{
   438                 CharBuffer cc = CharBuffer.wrap(convChar);
   436                 CharBuffer cc = CharBuffer.wrap(convChar);
   439                 ByteBuffer bb = ByteBuffer.allocate(4);
   437                 ByteBuffer bb = ByteBuffer.wrap(convByte);
   440                 ISOEncoder.encode(cc, bb, true);
   438                 ISOEncoder.encode(cc, bb, true);
   441                 bb.flip();
   439                 bb.flip();
   442                 converted = bb.remaining();
   440                 converted = bb.remaining();
   443                 bb.get(convByte,0,converted);
       
   444             } catch(Exception e) {
   441             } catch(Exception e) {
   445                 return -1;
   442                 return -1;
   446             }
   443             }
   447 
   444 
   448             if (converted == 2) {
   445             if (converted == 2) {
   449                 if (!SODesDefined) {
   446                 if (!SODesDefined) {
   450                     newSODesDefined = true;
   447                     newSODesDefined = true;
   451                     ebyte[0] = ISO_ESC;
   448                     ebyte[0] = ISO_ESC;
   452                     tmpByte = SODesig.getBytes();
   449                     System.arraycopy(SODesig, 0, ebyte, 1, SODesig.length);
   453                     System.arraycopy(tmpByte,0,ebyte,1,tmpByte.length);
   450                     index = SODesig.length + 1;
   454                     index = tmpByte.length+1;
       
   455                 }
   451                 }
   456                 if (!shiftout) {
   452                 if (!shiftout) {
   457                     newshiftout = true;
   453                     newshiftout = true;
   458                     ebyte[index++] = ISO_SO;
   454                     ebyte[index++] = ISO_SO;
   459                 }
   455                 }
   463                 if(convByte[0] == SS2) {
   459                 if(convByte[0] == SS2) {
   464                     if (convByte[1] == PLANE2) {
   460                     if (convByte[1] == PLANE2) {
   465                         if (!SS2DesDefined) {
   461                         if (!SS2DesDefined) {
   466                             newSS2DesDefined = true;
   462                             newSS2DesDefined = true;
   467                             ebyte[0] = ISO_ESC;
   463                             ebyte[0] = ISO_ESC;
   468                             tmpByte = SS2Desig.getBytes();
   464                             System.arraycopy(SS2Desig, 0, ebyte, 1, SS2Desig.length);
   469                             System.arraycopy(tmpByte, 0, ebyte, 1, tmpByte.length);
   465                             index = SS2Desig.length + 1;
   470                             index = tmpByte.length+1;
       
   471                         }
   466                         }
   472                         ebyte[index++] = ISO_ESC;
   467                         ebyte[index++] = ISO_ESC;
   473                         ebyte[index++] = ISO_SS2_7;
   468                         ebyte[index++] = ISO_SS2_7;
   474                         ebyte[index++] = (byte)(convByte[2] & 0x7f);
   469                         ebyte[index++] = (byte)(convByte[2] & 0x7f);
   475                         ebyte[index++] = (byte)(convByte[3] & 0x7f);
   470                         ebyte[index++] = (byte)(convByte[3] & 0x7f);
   476                     } else if (convByte[1] == PLANE3) {
   471                     } else if (convByte[1] == PLANE3) {
   477                         if(!SS3DesDefined){
   472                         if(!SS3DesDefined){
   478                             newSS3DesDefined = true;
   473                             newSS3DesDefined = true;
   479                             ebyte[0] = ISO_ESC;
   474                             ebyte[0] = ISO_ESC;
   480                             tmpByte = SS3Desig.getBytes();
   475                             System.arraycopy(SS3Desig, 0, ebyte, 1, SS3Desig.length);
   481                             System.arraycopy(tmpByte, 0, ebyte, 1, tmpByte.length);
   476                             index = SS3Desig.length + 1;
   482                             index = tmpByte.length+1;
       
   483                         }
   477                         }
   484                         ebyte[index++] = ISO_ESC;
   478                         ebyte[index++] = ISO_ESC;
   485                         ebyte[index++] = ISO_SS3_7;
   479                         ebyte[index++] = ISO_SS3_7;
   486                         ebyte[index++] = (byte)(convByte[2] & 0x7f);
   480                         ebyte[index++] = (byte)(convByte[2] & 0x7f);
   487                         ebyte[index++] = (byte)(convByte[3] & 0x7f);
   481                         ebyte[index++] = (byte)(convByte[3] & 0x7f);
   558                 src.position(sp - src.arrayOffset());
   552                 src.position(sp - src.arrayOffset());
   559                 dst.position(dp - dst.arrayOffset());
   553                 dst.position(dp - dst.arrayOffset());
   560              }
   554              }
   561         }
   555         }
   562 
   556 
   563 
       
   564         private CoderResult encodeBufferLoop(CharBuffer src,
   557         private CoderResult encodeBufferLoop(CharBuffer src,
   565                                              ByteBuffer dst)
   558                                              ByteBuffer dst)
   566         {
   559         {
   567             int outputSize = 0;
   560             int outputSize = 0;
   568             byte[]  outputByte = new byte[8];
   561             byte[]  outputByte = new byte[8];