I came across this question while trying to find out if UTF-8 is available. So thanks for the link.
I agree that there is no need to throw a checked exception when it comes to encoding and decoding using a specific character set that is guaranteed to be available. If the character set was the passed variable, I would probably throw an UnsupportedEncodingException.
This is what I am doing in a similar part of Android code:
public static String encode(String input) { try { return URLEncoder.encode(input, CharEncoding.UTF_8); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
CharEncoding.UTF_8 is just a String Apache constant for "UTF-8".
Judge The mental proposal to use StandardCharsets.UTF_8 excellent, but for those of us who are developing Android, it is only available on SDK 19 (KitKat) and higher.
spaaarky21
source share