Avoid UnsupportedEncodingException & use const from StandardCharsets (#11948)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp
2022-01-03 16:05:08 +01:00
committed by GitHub
parent 3f54327d5a
commit 167f8ebc49
52 changed files with 180 additions and 414 deletions

View File

@@ -15,7 +15,6 @@ package org.openhab.binding.amazonechocontrol.internal;
import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.net.URLEncoder;
@@ -88,11 +87,11 @@ public class AccountServlet extends HttpServlet {
this.gson = gson;
try {
servletUrlWithoutRoot = "amazonechocontrol/" + URLEncoder.encode(id, "UTF8");
servletUrlWithoutRoot = "amazonechocontrol/" + URLEncoder.encode(id, StandardCharsets.UTF_8);
servletUrl = "/" + servletUrlWithoutRoot;
httpService.registerServlet(servletUrl, this, null, httpService.createDefaultHttpContext());
} catch (UnsupportedEncodingException | NamespaceException | ServletException e) {
} catch (NamespaceException | ServletException e) {
throw new IllegalStateException(e.getMessage());
}
}
@@ -340,12 +339,7 @@ public class AccountServlet extends HttpServlet {
String[] elements = param.split("=");
if (elements.length == 2) {
String name = elements[0];
String value = "";
try {
value = URLDecoder.decode(elements[1], "UTF8");
} catch (UnsupportedEncodingException e) {
logger.info("Unsupported encoding", e);
}
String value = URLDecoder.decode(elements[1], StandardCharsets.UTF_8);
map.put(name, value);
}
}