Is there a way to find out if an encoding is supported or not? E. g. a method like this:
isSupported("UTF-8") == true
and
isSupported("UTF-13") == false
I need this to validate if the Content-Disposition-Header of my MimeMessages is correct.
Try the following:
Charset.isSupported("UTF-8")
this method may throw RuntimeExceptions when name is null or the name is invalid.
boolean isCharsetSupported(String name) {
try {
Charset.forName(name);
return true;
} catch (UnsupportedCharsetException | IllegalCharsetNameException | IllegalArgumentException e) {
return false;
}
}
or without a try/catch block:
boolean isCharsetSupported(String name) {
return Charset.availableCharsets().keySet().contains(name);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With