Java Utililty Methods Charset Guess

List of utility methods to do Charset Guess

Description

The list of methods to do Charset Guess are organized into topic(s).

Method

StringgetCharset(File file)
get Charset
String code = "GBK";
FileInputStream fis = null;
try {
    byte[] head = new byte[3];
    fis = new FileInputStream(file);
    fis.read(head);
    code = getCharset(head);
} catch (Exception e) {
...
StringgetCharset(Object resource)
get Charset
if (resource instanceof InputStreamReader) {
    return ((InputStreamReader) resource).getEncoding();
return null;
WritergetCharsetFileWriter(File file, String charset)
get Charset File Writer
return new OutputStreamWriter(new FileOutputStream(file), charset);
StringgetCharsetFromBytes(byte abyte0[])
get Charset From Bytes
if (abyte0 == null)
    return null;
String s = null;
try {
    s = new String(abyte0, "ISO-8859-1");
} catch (UnsupportedEncodingException unsupportedencodingexception) {
if (s == null) {
...
StringgetCharSetStr(String str, String oldCharSet, String newCharSet)
get Char Set Str
if (str == "" || str == null) {
    return "";
try {
    str = new String(str.getBytes(oldCharSet), newCharSet);
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
return str;
chargetPYIndexChar(char strChinese, boolean bUpCase)
get PY Index Char
int charGBK = strChinese;
char result;
if (charGBK >= 45217 && charGBK <= 45252)
    result = 'A';
else if (charGBK >= 45253 && charGBK <= 45760)
    result = 'B';
else if (charGBK >= 45761 && charGBK <= 46317 || charGBK == 55000)
    result = 'C';
...