src/share/classes/sun/nio/cs/ext/DoubleByte.java

Print this page




 232                 dst[dp++] = c;
 233             }
 234             return dp;
 235         }
 236 
 237         public void implReset() {
 238             super.implReset();
 239         }
 240 
 241         public CoderResult implFlush(CharBuffer out) {
 242             return super.implFlush(out);
 243         }
 244 
 245         // decode loops are not using decodeSingle/Double() for performance
 246         // reason.
 247         public char decodeSingle(int b) {
 248             return b2cSB[b];
 249         }
 250 
 251         public char decodeDouble(int b1, int b2) {
 252             if (b2 < b2Min || b2 > b2Max)

 253                 return UNMAPPABLE_DECODING;
 254             return  b2c[b1][b2 - b2Min];
 255         }
 256 
 257     }
 258 
 259     // IBM_EBCDIC_DBCS
 260     public static class Decoder_EBCDIC extends Decoder {
 261         private static final int SBCS = 0;
 262         private static final int DBCS = 1;
 263         private static final int SO = 0x0e;
 264         private static final int SI = 0x0f;
 265         private int  currentState;
 266 
 267         Decoder_EBCDIC(Charset cs,
 268                        char[][] b2c, char[] b2cSB, int b2Min, int b2Max) {
 269             super(cs, b2c, b2cSB, b2Min, b2Max);
 270         }
 271 
 272         public void implReset() {
 273             currentState = SBCS;
 274         }
 275 
 276         // Check validity of dbcs ebcdic byte pair values


 418                         if (c == UNMAPPABLE_DECODING)
 419                             c = repl;
 420                     } else {
 421                         if (sl == sp) {
 422                             c = repl;
 423                         } else {
 424                             int b2 = src[sp++] & 0xff;
 425                             if (b2 < b2Min || b2 > b2Max ||
 426                                 (c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) {
 427                                 c = repl;
 428                             }
 429                         }
 430                     }
 431                     dst[dp++] = c;
 432                 }
 433             }
 434             return dp;
 435         }
 436     }
 437 
 438     // EBCDIC_DBCS_ONLY
 439     public static class Decoder_EBCDIC_DBCSONLY extends Decoder {
 440         static final char[] b2cSB;
 441         static {
 442             b2cSB = new char[0x100];
 443             Arrays.fill(b2cSB, UNMAPPABLE_DECODING);
 444         }
 445         Decoder_EBCDIC_DBCSONLY(Charset cs, char[][] b2c, int b2Min, int b2Max) {
 446             super(cs, 0.5f, 1.0f, b2c, b2cSB, b2Min, b2Max);
 447         }
 448     }
 449 
 450     // EUC_SIMPLE
 451     // The only thing we need to "override" is to check SS2/SS3 and
 452     // return "malformed" if found
 453     public static class Decoder_EUC_SIM extends Decoder {
 454         private final int SS2 =  0x8E;
 455         private final int SS3 =  0x8F;
 456 
 457         Decoder_EUC_SIM(Charset cs,
 458                         char[][] b2c, char[] b2cSB, int b2Min, int b2Max) {
 459             super(cs, b2c, b2cSB, b2Min, b2Max);
 460         }
 461 
 462         // No support provided for G2/G3 for SimpleEUC
 463         protected CoderResult crMalformedOrUnderFlow(int b) {
 464             if (b == SS2 || b == SS3 )
 465                 return CoderResult.malformedForLength(1);
 466             return CoderResult.UNDERFLOW;


 710                 }
 711             }
 712 
 713             if (c2bNR != null) {
 714                 // add c->b only nr entries
 715                 for (int i = 0; i < c2bNR.length(); i += 2) {
 716                     char b = c2bNR.charAt(i);
 717                     char c = c2bNR.charAt(i + 1);
 718                     int index = (c >> 8);
 719                     if (c2bIndex[index] == 0) {
 720                         c2bIndex[index] = (char)off;
 721                         off += 0x100;
 722                     }
 723                     index = c2bIndex[index] + (c & 0xff);
 724                     c2b[index] = b;
 725                 }
 726             }
 727         }
 728     }
 729 
 730     public static class Encoder_EBCDIC_DBCSONLY extends Encoder {
 731         Encoder_EBCDIC_DBCSONLY(Charset cs, byte[] repl,
 732                                 char[] c2b, char[] c2bIndex) {
 733             super(cs, 2.0f, 2.0f, repl, c2b, c2bIndex);
 734         }
 735 
 736         public int encodeChar(char ch) {
 737             int bb = super.encodeChar(ch);
 738             if (bb <= MAX_SINGLEBYTE)
 739                 return UNMAPPABLE_ENCODING;
 740             return bb;
 741         }
 742     }
 743 


 744     public static class Encoder_EBCDIC extends Encoder {
 745         static final int SBCS = 0;
 746         static final int DBCS = 1;
 747         static final byte SO = 0x0e;
 748         static final byte SI = 0x0f;
 749 
 750         protected int  currentState = SBCS;
 751 
 752         Encoder_EBCDIC(Charset cs, char[] c2b, char[] c2bIndex) {
 753             super(cs, 4.0f, 5.0f, new byte[] {(byte)0x6f}, c2b, c2bIndex);
 754         }
 755 
 756         protected void implReset() {
 757             currentState = SBCS;
 758         }
 759 
 760         protected CoderResult implFlush(ByteBuffer out) {
 761             if (currentState == DBCS) {
 762                 if (out.remaining() < 1)
 763                     return CoderResult.OVERFLOW;


 894                          dst[dp++] = SI;
 895                     }
 896                     dst[dp++] = (byte)bb;
 897                 }
 898             }
 899 
 900             if (currentState == DBCS) {
 901                  currentState = SBCS;
 902                  dst[dp++] = SI;
 903             }
 904             return dp;
 905         }
 906     }
 907 
 908     // EUC_SIMPLE
 909     public static class Encoder_EUC_SIM extends Encoder {
 910         Encoder_EUC_SIM(Charset cs, char[] c2b, char[] c2bIndex) {
 911             super(cs, c2b, c2bIndex);
 912         }
 913     }

 914 }


 232                 dst[dp++] = c;
 233             }
 234             return dp;
 235         }
 236 
 237         public void implReset() {
 238             super.implReset();
 239         }
 240 
 241         public CoderResult implFlush(CharBuffer out) {
 242             return super.implFlush(out);
 243         }
 244 
 245         // decode loops are not using decodeSingle/Double() for performance
 246         // reason.
 247         public char decodeSingle(int b) {
 248             return b2cSB[b];
 249         }
 250 
 251         public char decodeDouble(int b1, int b2) {
 252             if (b1 < 0 || b1 > b2c.length ||
 253                 b2 < b2Min || b2 > b2Max)
 254                 return UNMAPPABLE_DECODING;
 255             return  b2c[b1][b2 - b2Min];
 256         }

 257     }
 258 
 259     // IBM_EBCDIC_DBCS
 260     public static class Decoder_EBCDIC extends Decoder {
 261         private static final int SBCS = 0;
 262         private static final int DBCS = 1;
 263         private static final int SO = 0x0e;
 264         private static final int SI = 0x0f;
 265         private int  currentState;
 266 
 267         Decoder_EBCDIC(Charset cs,
 268                        char[][] b2c, char[] b2cSB, int b2Min, int b2Max) {
 269             super(cs, b2c, b2cSB, b2Min, b2Max);
 270         }
 271 
 272         public void implReset() {
 273             currentState = SBCS;
 274         }
 275 
 276         // Check validity of dbcs ebcdic byte pair values


 418                         if (c == UNMAPPABLE_DECODING)
 419                             c = repl;
 420                     } else {
 421                         if (sl == sp) {
 422                             c = repl;
 423                         } else {
 424                             int b2 = src[sp++] & 0xff;
 425                             if (b2 < b2Min || b2 > b2Max ||
 426                                 (c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) {
 427                                 c = repl;
 428                             }
 429                         }
 430                     }
 431                     dst[dp++] = c;
 432                 }
 433             }
 434             return dp;
 435         }
 436     }
 437 
 438     // DBCS_ONLY
 439     public static class Decoder_DBCSONLY extends Decoder {
 440         static final char[] b2cSB_UNMAPPABLE;
 441         static {
 442             b2cSB_UNMAPPABLE = new char[0x100];
 443             Arrays.fill(b2cSB_UNMAPPABLE, UNMAPPABLE_DECODING);
 444         }
 445         Decoder_DBCSONLY(Charset cs, char[][] b2c, char[] b2cSB, int b2Min, int b2Max) {
 446             super(cs, 0.5f, 1.0f, b2c, b2cSB_UNMAPPABLE, b2Min, b2Max);
 447         }
 448     }
 449 
 450     // EUC_SIMPLE
 451     // The only thing we need to "override" is to check SS2/SS3 and
 452     // return "malformed" if found
 453     public static class Decoder_EUC_SIM extends Decoder {
 454         private final int SS2 =  0x8E;
 455         private final int SS3 =  0x8F;
 456 
 457         Decoder_EUC_SIM(Charset cs,
 458                         char[][] b2c, char[] b2cSB, int b2Min, int b2Max) {
 459             super(cs, b2c, b2cSB, b2Min, b2Max);
 460         }
 461 
 462         // No support provided for G2/G3 for SimpleEUC
 463         protected CoderResult crMalformedOrUnderFlow(int b) {
 464             if (b == SS2 || b == SS3 )
 465                 return CoderResult.malformedForLength(1);
 466             return CoderResult.UNDERFLOW;


 710                 }
 711             }
 712 
 713             if (c2bNR != null) {
 714                 // add c->b only nr entries
 715                 for (int i = 0; i < c2bNR.length(); i += 2) {
 716                     char b = c2bNR.charAt(i);
 717                     char c = c2bNR.charAt(i + 1);
 718                     int index = (c >> 8);
 719                     if (c2bIndex[index] == 0) {
 720                         c2bIndex[index] = (char)off;
 721                         off += 0x100;
 722                     }
 723                     index = c2bIndex[index] + (c & 0xff);
 724                     c2b[index] = b;
 725                 }
 726             }
 727         }
 728     }
 729 
 730     public static class Encoder_DBCSONLY extends Encoder {
 731         Encoder_DBCSONLY(Charset cs, byte[] repl,
 732                          char[] c2b, char[] c2bIndex) {
 733             super(cs, 2.0f, 2.0f, repl, c2b, c2bIndex);
 734         }
 735 
 736         public int encodeChar(char ch) {
 737             int bb = super.encodeChar(ch);
 738             if (bb <= MAX_SINGLEBYTE)
 739                 return UNMAPPABLE_ENCODING;
 740             return bb;
 741         }
 742     }
 743 
 744 
 745 
 746     public static class Encoder_EBCDIC extends Encoder {
 747         static final int SBCS = 0;
 748         static final int DBCS = 1;
 749         static final byte SO = 0x0e;
 750         static final byte SI = 0x0f;
 751 
 752         protected int  currentState = SBCS;
 753 
 754         Encoder_EBCDIC(Charset cs, char[] c2b, char[] c2bIndex) {
 755             super(cs, 4.0f, 5.0f, new byte[] {(byte)0x6f}, c2b, c2bIndex);
 756         }
 757 
 758         protected void implReset() {
 759             currentState = SBCS;
 760         }
 761 
 762         protected CoderResult implFlush(ByteBuffer out) {
 763             if (currentState == DBCS) {
 764                 if (out.remaining() < 1)
 765                     return CoderResult.OVERFLOW;


 896                          dst[dp++] = SI;
 897                     }
 898                     dst[dp++] = (byte)bb;
 899                 }
 900             }
 901 
 902             if (currentState == DBCS) {
 903                  currentState = SBCS;
 904                  dst[dp++] = SI;
 905             }
 906             return dp;
 907         }
 908     }
 909 
 910     // EUC_SIMPLE
 911     public static class Encoder_EUC_SIM extends Encoder {
 912         Encoder_EUC_SIM(Charset cs, char[] c2b, char[] c2bIndex) {
 913             super(cs, c2b, c2bIndex);
 914         }
 915     }
 916 
 917 }