mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-25 07:23:03 +00:00
Detect big endian as well
This commit is contained in:
parent
6dca1355a3
commit
46bf44fe03
1 changed files with 10 additions and 1 deletions
|
@ -133,6 +133,7 @@ public class CharsetHelper {
|
|||
}
|
||||
|
||||
static Boolean isUTF16LE(BufferedInputStream bis) throws IOException {
|
||||
// https://en.wikipedia.org/wiki/Endianness
|
||||
byte[] bytes = new byte[64];
|
||||
bis.mark(bytes.length);
|
||||
try {
|
||||
|
@ -153,7 +154,15 @@ public class CharsetHelper {
|
|||
even++;
|
||||
else
|
||||
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 {
|
||||
bis.reset();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue