EML: show detected charset

This commit is contained in:
M66B
2021-06-25 09:09:12 +02:00
parent aa7edaf99d
commit a56005b95d
2 changed files with 35 additions and 1 deletions

View File

@@ -48,11 +48,13 @@ public class CharsetHelper {
static boolean isUTF8(String text) {
// Get extended ASCII characters
byte[] octets = text.getBytes(StandardCharsets.ISO_8859_1);
return isUTF8(octets);
}
static boolean isUTF8(byte[] octets) {
CharsetDecoder utf8Decoder = StandardCharsets.UTF_8.newDecoder()
.onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPORT);
try {
utf8Decoder.decode(ByteBuffer.wrap(octets));
return true;