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
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user