ByteToCharJISAutoDetect.java revision 2362
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public class ByteToCharJISAutoDetect extends ByteToCharConverter {
private final static int EUCJP_MASK = 0x01;
private final static int SJIS2B_MASK = 0x02;
private final static int SJIS1B_MASK = 0x04;
private final static int EUCJP_KANA1_MASK = 0x08;
private final static int EUCJP_KANA2_MASK = 0x10;
private static byte[] maskTable1;
private static byte[] maskTable2;
private final static int SS2 = 0x8e;
private final static int SS3 = 0x8f;
// SJISName is set to either "SJIS" or "MS932"
public ByteToCharJISAutoDetect() {
super();
defaultConv = new ByteToCharISO8859_1();
}
{
badInputLength = 0;
if(detectedConv != null)
else
}
/**
* Character conversion
*/
{
int num = 0;
try {
if (detectedConv == null) {
int euckana = 0;
int ss2count = 0;
int firstmask = 0;
int secondmask = 0;
int cnt;
boolean nonAsciiFound = false;
firstmask = 0;
secondmask = 0;
int byte2;
// TODO: should check valid escape sequences!
if (byte1 == 0x1b) {
convName = "ISO2022JP";
break;
}
// Try to convert all leading ASCII characters.
throw new ConversionBufferFullException();
byteOff++;
num++;
continue;
}
// We can no longer convert ASCII.
nonAsciiFound = true;
ss2count++;
if (firstmask != 0) {
if (mask == EUCJP_MASK) {
break;
}
break;
}
// If the first byte is a SS3 and the third byte
// is not an EUC byte, it should be SJIS.
// Otherwise, we can't determine it yet, but it's
// very likely SJIS. So we don't take the EUCJP CS3
// character boundary. If we tried both
// possibilities here, it might be able to be
// determined correctly.
} else
}
euckana++;
} else {
break;
}
}
}
}
else
}
try {
} catch (UnsupportedEncodingException e){
detectedConv = null;
}
}
}
} catch (ConversionBufferFullException bufferFullException) {
throw bufferFullException;
} catch (Exception e) {
// If we fail to detect the converter needed for any reason,
// use the default converter.
}
// If we've converted all ASCII characters, then return.
return num;
}
if(detectedConv != null) {
try {
} finally {
}
} else {
try {
} finally {
}
}
return num;
}
public void reset() {
if(detectedConv != null) {
detectedConv = null;
} else
defaultConv.reset();
}
public String getCharacterEncoding() {
return "JISAutoDetect";
}
String s = getCharacterEncoding();
if (detectedConv != null) {
} else {
s += "[unknown]";
}
return s;
}
}