Avoid UnsupportedEncodingException & use const from StandardCharsets (#11948)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
committed by
GitHub
parent
3f54327d5a
commit
167f8ebc49
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.heos.internal.json;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
@@ -90,10 +89,6 @@ public class HeosJsonParser {
|
||||
}
|
||||
|
||||
private static String decode(String encoded) {
|
||||
try {
|
||||
return URLDecoder.decode(encoded, StandardCharsets.UTF_8.name());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new IllegalStateException("Impossible: UTF-8 is a required encoding", e);
|
||||
}
|
||||
return URLDecoder.decode(encoded, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.heos.internal.resources;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@@ -322,12 +321,8 @@ public class HeosCommands {
|
||||
}
|
||||
|
||||
private static String urlEncode(String username) {
|
||||
try {
|
||||
String encoded = URLEncoder.encode(username, StandardCharsets.UTF_8.toString());
|
||||
// however it cannot handle escaped @ signs
|
||||
return encoded.replace("%40", "@");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new IllegalStateException("UTF-8 is not supported, bailing out");
|
||||
}
|
||||
String encoded = URLEncoder.encode(username, StandardCharsets.UTF_8);
|
||||
// however it cannot handle escaped @ signs
|
||||
return encoded.replace("%40", "@");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user