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.magentatv.internal;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -100,8 +99,6 @@ public class MagentaTVBindingConstants {
|
||||
public static final int DEF_REFRESH_INTERVAL_SEC = 60;
|
||||
public static final int NETWORK_TIMEOUT_MS = 3000;
|
||||
|
||||
public static final String UTF_8 = StandardCharsets.UTF_8.name();
|
||||
|
||||
public static final String HEADER_CONTENT_TYPE = "Content-Type";
|
||||
public static final String HEADER_HOST = "HOST";
|
||||
public static final String HEADER_ACCEPT = "Accept";
|
||||
|
||||
@@ -15,7 +15,7 @@ package org.openhab.binding.magentatv.internal.handler;
|
||||
import static org.openhab.binding.magentatv.internal.MagentaTVBindingConstants.*;
|
||||
import static org.openhab.binding.magentatv.internal.MagentaTVUtil.*;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.MessageFormat;
|
||||
@@ -480,7 +480,7 @@ public class MagentaTVControl {
|
||||
*/
|
||||
public static String computeMD5(String unhashed) {
|
||||
try {
|
||||
byte[] bytesOfMessage = unhashed.getBytes(UTF_8);
|
||||
byte[] bytesOfMessage = unhashed.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
MessageDigest md5 = MessageDigest.getInstance(HASH_ALGORITHM_MD5);
|
||||
byte[] hash = md5.digest(bytesOfMessage);
|
||||
@@ -490,7 +490,7 @@ public class MagentaTVControl {
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import static org.openhab.binding.magentatv.internal.MagentaTVBindingConstants.*
|
||||
import static org.openhab.binding.magentatv.internal.MagentaTVUtil.substringBetween;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
@@ -139,7 +140,7 @@ public class MagentaTVNotifyServlet extends HttpServlet {
|
||||
} finally {
|
||||
// send response
|
||||
if (response != null) {
|
||||
response.setCharacterEncoding(UTF_8);
|
||||
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
response.getWriter().write("");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ package org.openhab.binding.magentatv.internal.network;
|
||||
import static org.openhab.binding.magentatv.internal.MagentaTVBindingConstants.*;
|
||||
import static org.openhab.binding.magentatv.internal.MagentaTVUtil.*;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpCookie;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -291,11 +290,6 @@ public class MagentaTVOAuth {
|
||||
}
|
||||
|
||||
private String urlEncode(String url) {
|
||||
try {
|
||||
return URLEncoder.encode(url, UTF_8);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
logger.warn("OAuth: Unable to URL encode string {}", url, e);
|
||||
return "";
|
||||
}
|
||||
return URLEncoder.encode(url, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user