src/share/classes/sun/io/ByteToCharEUC_TW.java

Print this page

        

*** 37,71 **** private final byte G2 = 2; private final byte G3 = 3; private final byte G4 = 4; private final byte MSB = (byte) 0x80; private final byte SS2 = (byte) 0x8E; - private final byte P2 = (byte) 0xA2; - private final byte P3 = (byte) 0xA3; - protected final char REPLACE_CHAR = '\uFFFD'; - private byte firstByte = 0, state = G0; - public static String unicodeCNS2, unicodeCNS3; - private static String unicodeCNS4, unicodeCNS5, unicodeCNS6; - private static String unicodeCNS7, unicodeCNS15; - private int cnsPlane = 0; - private final static EUC_TW nioCoder = new EUC_TW(); ! public static String unicodeCNS1 = nioCoder.getUnicodeCNS1(); - static String[] cnsChars = { - unicodeCNS2 = nioCoder.getUnicodeCNS2(), - unicodeCNS3 = nioCoder.getUnicodeCNS3(), - unicodeCNS4 = nioCoder.getUnicodeCNS4(), - unicodeCNS5 = nioCoder.getUnicodeCNS5(), - unicodeCNS6 = nioCoder.getUnicodeCNS6(), - unicodeCNS7 = nioCoder.getUnicodeCNS7(), - unicodeCNS15 = nioCoder.getUnicodeCNS15() - }; - public ByteToCharEUC_TW() { } public int flush(char[] output, int outStart, int outEnd) throws MalformedInputException --- 37,52 ---- private final byte G2 = 2; private final byte G3 = 3; private final byte G4 = 4; private final byte MSB = (byte) 0x80; private final byte SS2 = (byte) 0x8E; private byte firstByte = 0, state = G0; private int cnsPlane = 0; ! private EUC_TW.Decoder dec = (EUC_TW.Decoder)(new EUC_TW().newDecoder()); public ByteToCharEUC_TW() { } public int flush(char[] output, int outStart, int outEnd) throws MalformedInputException
*** 79,88 **** --- 60,70 ---- reset(); return 0; } public void reset() { + dec.reset(); state = G0; firstByte = 0; byteOff = charOff = 0; }
*** 93,116 **** char[] output, int outOff, int outEnd) throws UnknownCharacterException, MalformedInputException, ConversionBufferFullException { int inputSize = 0; ! char outputChar = (char) 0; byteOff = inOff; charOff = outOff; cnsPlane = 3; while (byteOff < inEnd) { if (charOff >= outEnd) throw new ConversionBufferFullException(); ! switch (state) { case G0: if ( (input[byteOff] & MSB) == 0) { // ASCII ! outputChar = (char) input[byteOff]; } else if (input[byteOff] == SS2) { // Codeset 2 state = G2; } else { // Codeset 1 firstByte = input[byteOff]; state = G1; --- 75,99 ---- char[] output, int outOff, int outEnd) throws UnknownCharacterException, MalformedInputException, ConversionBufferFullException { int inputSize = 0; ! char[] c1 = new char[1]; byteOff = inOff; charOff = outOff; cnsPlane = 3; while (byteOff < inEnd) { if (charOff >= outEnd) throw new ConversionBufferFullException(); ! char[] outputChar = null; switch (state) { case G0: if ( (input[byteOff] & MSB) == 0) { // ASCII ! outputChar = c1; ! outputChar[0] = (char) input[byteOff]; } else if (input[byteOff] == SS2) { // Codeset 2 state = G2; } else { // Codeset 1 firstByte = input[byteOff]; state = G1;
*** 117,129 **** } break; case G1: inputSize = 2; if ( (input[byteOff] & MSB) != 0) { // 2nd byte ! cnsPlane = 1; ! outputChar = convToUnicode(firstByte, ! input[byteOff], unicodeCNS1); } else { // Error badInputLength = 1; throw new MalformedInputException(); } firstByte = 0; --- 100,113 ---- } break; case G1: inputSize = 2; if ( (input[byteOff] & MSB) != 0) { // 2nd byte ! cnsPlane = 0; ! outputChar = dec.toUnicode(firstByte & 0xff, ! input[byteOff] & 0xff, ! cnsPlane); } else { // Error badInputLength = 1; throw new MalformedInputException(); } firstByte = 0;
*** 152,188 **** throw new MalformedInputException(); } break; case G4: if ( (input[byteOff] & MSB) != 0) { // 2nd byte ! outputChar = convToUnicode(firstByte, ! input[byteOff], ! cnsChars[cnsPlane - 2]); } else { // Error badInputLength = 3; throw new MalformedInputException(); } firstByte = 0; state = G0; break; } byteOff++; ! ! if (outputChar != (char) 0) { ! if (outputChar == REPLACE_CHAR) { ! if (subMode) // substitution enabled ! outputChar = subChars[0]; ! else { badInputLength = inputSize; throw new UnknownCharacterException(); } } ! output[charOff++] = outputChar; ! outputChar = 0; } } - return charOff - outOff; } /** --- 136,170 ---- throw new MalformedInputException(); } break; case G4: if ( (input[byteOff] & MSB) != 0) { // 2nd byte ! outputChar = dec.toUnicode(firstByte & 0xff, ! input[byteOff] & 0xff, ! cnsPlane - 1); } else { // Error badInputLength = 3; throw new MalformedInputException(); } firstByte = 0; state = G0; break; } byteOff++; ! if (state == G0) { ! if (outputChar == null) { ! if (subMode) { // substitution enabled ! outputChar = c1; ! outputChar[0] = subChars[0]; ! } else { badInputLength = inputSize; throw new UnknownCharacterException(); } } ! output[charOff++] = outputChar[0]; } } return charOff - outOff; } /**
*** 189,215 **** * Return the character set ID */ public String getCharacterEncoding() { return "EUC_TW"; } - - protected char convToUnicode(byte byte1, byte byte2, String table) - { - int index; - - if ((byte1 & 0xff) < 0xa1 || (byte2 & 0xff) < 0xa1 || - (byte1 & 0xff) > 0xfe || (byte2 & 0xff) > 0xfe) - return REPLACE_CHAR; - index = (((byte1 & 0xff) - 0xa1) * 94) + (byte2 & 0xff) - 0xa1; - if (index < 0 || index >= table.length()) - return REPLACE_CHAR; - - // Planes 3 and above containing zero value lead byte - // to accommodate surrogates for mappings which decode to a surrogate - // pair - - if (this.cnsPlane >= 3) - index = (index * 2) + 1; - - return table.charAt(index); - } } --- 171,176 ----