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

@@ -14,7 +14,6 @@ package org.openhab.binding.foobot.internal;
import static org.openhab.binding.foobot.internal.FoobotBindingConstants.*;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
@@ -92,12 +91,12 @@ public class FoobotApiConnector {
public synchronized List<FoobotDevice> getAssociatedDevices(String username) throws FoobotApiException {
try {
final String url = URL_TO_FETCH_DEVICES.replace("%username%",
URLEncoder.encode(username, StandardCharsets.UTF_8.toString()));
URLEncoder.encode(username, StandardCharsets.UTF_8));
logger.debug("URL = {}", url);
List<FoobotDevice> foobotDevices = GSON.fromJson(request(url, apiKey), FOOTBOT_DEVICE_LIST_TYPE);
return Objects.requireNonNull(foobotDevices);
} catch (JsonParseException | UnsupportedEncodingException e) {
} catch (JsonParseException e) {
throw new FoobotApiException(0, e.getMessage());
}
}
@@ -112,11 +111,11 @@ public class FoobotApiConnector {
public synchronized @Nullable FoobotJsonData getSensorData(String uuid) throws FoobotApiException {
try {
final String url = URL_TO_FETCH_SENSOR_DATA.replace("%uuid%",
URLEncoder.encode(uuid, StandardCharsets.UTF_8.toString()));
URLEncoder.encode(uuid, StandardCharsets.UTF_8));
logger.debug("URL = {}", url);
return GSON.fromJson(request(url, apiKey), FoobotJsonData.class);
} catch (JsonParseException | UnsupportedEncodingException e) {
} catch (JsonParseException e) {
throw new FoobotApiException(0, e.getMessage());
}
}