Android Utililty Methods File Encode Guess

List of utility methods to do File Encode Guess

Description

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

Method

StringguessEncoding(File file)
guess Encoding
FileInputStream fis = null;
try {
    fis = new FileInputStream(file);
    return FileUtil.guessEncoding(fis);
} catch (Exception e) {
    return null;
} finally {
    if (fis != null) {
...
StringguessEncoding(InputStream inputStream)
guess Encoding
try {
    byte[] rs = getFileByte(inputStream);
    String str = new String(rs, ENCODE_UTF8);
    if (str.equals(new String(str.getBytes(), ENCODE_UTF8))) {
        return ENCODE_UTF8;
    } else {
        str = new String(rs, ENCODE_GBK);
        if (str.equals(new String(str.getBytes(), ENCODE_GBK))) {
...
StringguessEncoding(File file)
Try to guess the file encoding.
byte[] b = readFile(file, 3);
String guess = null;
if (b[0] == (byte) 0xef && b[1] == (byte) 0xbb
        && b[2] == (byte) 0xbf)
    guess = UTF8;
else if (b[0] == (byte) 0xff && b[1] == (byte) 0xfe)
    guess = UTF16LE;
else if (b[0] == (byte) 0xfe && b[1] == (byte) 0xff)
...
StringgetEncodingOfXml(File file)
Try to find the encoding of a xml file.
byte[] bs = readFile(file, 150);
String encoding = "utf-8";
boolean findEncoding = false;
Map chars = Charset.availableCharsets();
Set keys = chars.keySet();
Iterator iterator = keys.iterator();
Pattern pattern = Pattern.compile("encoding=\"([^\"]*?)\"");
while (iterator.hasNext()) {
...