mirror of https://github.com/M66B/FairEmail.git
Detect big endian as well
This commit is contained in:
parent
6dca1355a3
commit
46bf44fe03
|
@ -133,6 +133,7 @@ public class CharsetHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
static Boolean isUTF16LE(BufferedInputStream bis) throws IOException {
|
static Boolean isUTF16LE(BufferedInputStream bis) throws IOException {
|
||||||
|
// https://en.wikipedia.org/wiki/Endianness
|
||||||
byte[] bytes = new byte[64];
|
byte[] bytes = new byte[64];
|
||||||
bis.mark(bytes.length);
|
bis.mark(bytes.length);
|
||||||
try {
|
try {
|
||||||
|
@ -153,7 +154,15 @@ public class CharsetHelper {
|
||||||
even++;
|
even++;
|
||||||
else
|
else
|
||||||
odd++;
|
odd++;
|
||||||
return (even < 30 * count / 100 / 2 && odd > 70 * count / 100 / 2);
|
|
||||||
|
int low = 30 * count / 100 / 2;
|
||||||
|
int high = 70 * count / 100 / 2;
|
||||||
|
|
||||||
|
if (even < low && odd > high)
|
||||||
|
return true; // Little endian
|
||||||
|
if (odd < low && even > high)
|
||||||
|
return false; // Big endian
|
||||||
|
return null; // Undetermined
|
||||||
} finally {
|
} finally {
|
||||||
bis.reset();
|
bis.reset();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue