Avoid UnsupportedEncodingException & use const from StandardCharsets (#11948)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>pull/11968/head
parent
3f54327d5a
commit
167f8ebc49
|
@ -15,7 +15,6 @@ package org.openhab.binding.amazonechocontrol.internal;
|
||||||
import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.*;
|
import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
@ -88,11 +87,11 @@ public class AccountServlet extends HttpServlet {
|
||||||
this.gson = gson;
|
this.gson = gson;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
servletUrlWithoutRoot = "amazonechocontrol/" + URLEncoder.encode(id, "UTF8");
|
servletUrlWithoutRoot = "amazonechocontrol/" + URLEncoder.encode(id, StandardCharsets.UTF_8);
|
||||||
servletUrl = "/" + servletUrlWithoutRoot;
|
servletUrl = "/" + servletUrlWithoutRoot;
|
||||||
|
|
||||||
httpService.registerServlet(servletUrl, this, null, httpService.createDefaultHttpContext());
|
httpService.registerServlet(servletUrl, this, null, httpService.createDefaultHttpContext());
|
||||||
} catch (UnsupportedEncodingException | NamespaceException | ServletException e) {
|
} catch (NamespaceException | ServletException e) {
|
||||||
throw new IllegalStateException(e.getMessage());
|
throw new IllegalStateException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -340,12 +339,7 @@ public class AccountServlet extends HttpServlet {
|
||||||
String[] elements = param.split("=");
|
String[] elements = param.split("=");
|
||||||
if (elements.length == 2) {
|
if (elements.length == 2) {
|
||||||
String name = elements[0];
|
String name = elements[0];
|
||||||
String value = "";
|
String value = URLDecoder.decode(elements[1], StandardCharsets.UTF_8);
|
||||||
try {
|
|
||||||
value = URLDecoder.decode(elements[1], "UTF8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.info("Unsupported encoding", e);
|
|
||||||
}
|
|
||||||
map.put(name, value);
|
map.put(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,6 @@ public class BigAssFanBindingConstants {
|
||||||
// Fans communicate on this port using both UDP (discovery) and TCP (commands)
|
// Fans communicate on this port using both UDP (discovery) and TCP (commands)
|
||||||
public static final int BAF_PORT = 31415;
|
public static final int BAF_PORT = 31415;
|
||||||
|
|
||||||
// Commands sent to/from fan are ASCII
|
|
||||||
public static final String CHARSET = "US-ASCII";
|
|
||||||
|
|
||||||
// BigAssFan Thing Type UIDs
|
// BigAssFan Thing Type UIDs
|
||||||
public static final ThingTypeUID THING_TYPE_FAN = new ThingTypeUID(BINDING_ID, "fan");
|
public static final ThingTypeUID THING_TYPE_FAN = new ThingTypeUID(BINDING_ID, "fan");
|
||||||
public static final ThingTypeUID THING_TYPE_LIGHT = new ThingTypeUID(BINDING_ID, "light");
|
public static final ThingTypeUID THING_TYPE_LIGHT = new ThingTypeUID(BINDING_ID, "light");
|
||||||
|
|
|
@ -12,16 +12,16 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.bigassfan.internal.discovery;
|
package org.openhab.binding.bigassfan.internal.discovery;
|
||||||
|
|
||||||
import static org.openhab.binding.bigassfan.internal.BigAssFanBindingConstants.*;
|
import static org.openhab.binding.bigassfan.internal.BigAssFanBindingConstants.BAF_PORT;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -60,12 +60,10 @@ public class DiscoveryListener {
|
||||||
rcvBuffer = new byte[256];
|
rcvBuffer = new byte[256];
|
||||||
rcvPacket = new DatagramPacket(rcvBuffer, rcvBuffer.length);
|
rcvPacket = new DatagramPacket(rcvBuffer, rcvBuffer.length);
|
||||||
bcastAddress = InetAddress.getByName(BCAST_ADDRESS);
|
bcastAddress = InetAddress.getByName(BCAST_ADDRESS);
|
||||||
bcastBuffer = POLL_MESSAGE.getBytes(CHARSET);
|
bcastBuffer = POLL_MESSAGE.getBytes(StandardCharsets.US_ASCII);
|
||||||
bcastPacket = new DatagramPacket(bcastBuffer, bcastBuffer.length, bcastAddress, BAF_PORT);
|
bcastPacket = new DatagramPacket(bcastBuffer, bcastBuffer.length, bcastAddress, BAF_PORT);
|
||||||
} catch (UnknownHostException uhe) {
|
} catch (UnknownHostException uhe) {
|
||||||
logger.warn("UnknownHostException sending poll request for fans: {}", uhe.getMessage(), uhe);
|
logger.warn("UnknownHostException sending poll request for fans: {}", uhe.getMessage(), uhe);
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.warn("Unable to convert buffer to string using {} charset", CHARSET, e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ import static org.openhab.binding.bigassfan.internal.BigAssFanBindingConstants.*
|
||||||
|
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
|
@ -24,6 +23,7 @@ import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.BufferOverflowException;
|
import java.nio.BufferOverflowException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
|
@ -611,13 +611,7 @@ public class BigAssFanHandler extends BaseThingHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("Sending message to {} at {}: {}", thing.getUID(), ipAddress, command);
|
logger.debug("Sending message to {} at {}: {}", thing.getUID(), ipAddress, command);
|
||||||
byte[] buffer;
|
byte[] buffer = command.getBytes(StandardCharsets.US_ASCII);
|
||||||
try {
|
|
||||||
buffer = command.getBytes(CHARSET);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.warn("Unable to convert to string using {} charset: {}", CHARSET, e.getMessage(), e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
conn.write(buffer);
|
conn.write(buffer);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -16,7 +16,6 @@ import java.beans.Introspector;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
@ -172,22 +171,17 @@ public class DenonMarantzHttpConnector extends DenonMarantzConnector {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
String url = cmdUrl + URLEncoder.encode(command, Charset.defaultCharset());
|
||||||
String url = cmdUrl + URLEncoder.encode(command, Charset.defaultCharset().displayName());
|
logger.trace("Calling url {}", url);
|
||||||
logger.trace("Calling url {}", url);
|
|
||||||
|
|
||||||
httpClient.newRequest(url).timeout(5, TimeUnit.SECONDS).send(new Response.CompleteListener() {
|
httpClient.newRequest(url).timeout(5, TimeUnit.SECONDS).send(new Response.CompleteListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onComplete(Result result) {
|
public void onComplete(Result result) {
|
||||||
if (result.getResponse().getStatus() != 200) {
|
if (result.getResponse().getStatus() != 200) {
|
||||||
logger.warn("Error {} while sending command", result.getResponse().getReason());
|
logger.warn("Error {} while sending command", result.getResponse().getReason());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.warn("Error sending command", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMain() throws IOException {
|
private void updateMain() throws IOException {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.TooManyListenersException;
|
import java.util.TooManyListenersException;
|
||||||
|
|
||||||
import org.openhab.binding.dscalarm.internal.config.IT100BridgeConfiguration;
|
import org.openhab.binding.dscalarm.internal.config.IT100BridgeConfiguration;
|
||||||
|
@ -98,7 +99,7 @@ public class IT100BridgeHandler extends DSCAlarmBaseBridgeHandler implements Ser
|
||||||
serialPort.enableReceiveThreshold(1);
|
serialPort.enableReceiveThreshold(1);
|
||||||
serialPort.disableReceiveTimeout();
|
serialPort.disableReceiveTimeout();
|
||||||
|
|
||||||
serialOutput = new OutputStreamWriter(serialPort.getOutputStream(), "US-ASCII");
|
serialOutput = new OutputStreamWriter(serialPort.getOutputStream(), StandardCharsets.US_ASCII);
|
||||||
serialInput = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
|
serialInput = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
|
||||||
|
|
||||||
setSerialEventHandler(this);
|
setSerialEventHandler(this);
|
||||||
|
|
|
@ -17,7 +17,6 @@ import static org.openhab.binding.ecobee.internal.EcobeeBindingConstants.*;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
@ -268,10 +267,10 @@ public class EcobeeApi implements AccessTokenRefreshListener {
|
||||||
return executePost(ECOBEE_THERMOSTAT_UPDATE_URL, GSON.toJson(request, ThermostatUpdateRequestDTO.class));
|
return executePost(ECOBEE_THERMOSTAT_UPDATE_URL, GSON.toJson(request, ThermostatUpdateRequestDTO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildQueryUrl(String baseUrl, String requestJson) throws UnsupportedEncodingException {
|
private String buildQueryUrl(String baseUrl, String requestJson) {
|
||||||
final StringBuilder urlBuilder = new StringBuilder(baseUrl);
|
final StringBuilder urlBuilder = new StringBuilder(baseUrl);
|
||||||
urlBuilder.append("?json=");
|
urlBuilder.append("?json=");
|
||||||
urlBuilder.append(URLEncoder.encode(requestJson, StandardCharsets.UTF_8.toString()));
|
urlBuilder.append(URLEncoder.encode(requestJson, StandardCharsets.UTF_8));
|
||||||
return urlBuilder.toString();
|
return urlBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.evohome.internal.api;
|
package org.openhab.binding.evohome.internal.api;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -200,17 +200,9 @@ public class EvohomeApiClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean authenticateWithUsername() {
|
private boolean authenticateWithUsername() {
|
||||||
boolean result = false;
|
String credentials = "Username=" + URLEncoder.encode(configuration.username, StandardCharsets.UTF_8) + "&"
|
||||||
|
+ "Password=" + URLEncoder.encode(configuration.password, StandardCharsets.UTF_8);
|
||||||
try {
|
return authenticate(credentials, "password");
|
||||||
String credentials = "Username=" + URLEncoder.encode(configuration.username, "UTF-8") + "&" + "Password="
|
|
||||||
+ URLEncoder.encode(configuration.password, "UTF-8");
|
|
||||||
result = authenticate(credentials, "password");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.error("Credential conversion failed", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean authenticateWithToken(String accessToken) {
|
private boolean authenticateWithToken(String accessToken) {
|
||||||
|
|
|
@ -14,7 +14,6 @@ package org.openhab.binding.foobot.internal;
|
||||||
|
|
||||||
import static org.openhab.binding.foobot.internal.FoobotBindingConstants.*;
|
import static org.openhab.binding.foobot.internal.FoobotBindingConstants.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
@ -92,12 +91,12 @@ public class FoobotApiConnector {
|
||||||
public synchronized List<FoobotDevice> getAssociatedDevices(String username) throws FoobotApiException {
|
public synchronized List<FoobotDevice> getAssociatedDevices(String username) throws FoobotApiException {
|
||||||
try {
|
try {
|
||||||
final String url = URL_TO_FETCH_DEVICES.replace("%username%",
|
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);
|
logger.debug("URL = {}", url);
|
||||||
|
|
||||||
List<FoobotDevice> foobotDevices = GSON.fromJson(request(url, apiKey), FOOTBOT_DEVICE_LIST_TYPE);
|
List<FoobotDevice> foobotDevices = GSON.fromJson(request(url, apiKey), FOOTBOT_DEVICE_LIST_TYPE);
|
||||||
return Objects.requireNonNull(foobotDevices);
|
return Objects.requireNonNull(foobotDevices);
|
||||||
} catch (JsonParseException | UnsupportedEncodingException e) {
|
} catch (JsonParseException e) {
|
||||||
throw new FoobotApiException(0, e.getMessage());
|
throw new FoobotApiException(0, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,11 +111,11 @@ public class FoobotApiConnector {
|
||||||
public synchronized @Nullable FoobotJsonData getSensorData(String uuid) throws FoobotApiException {
|
public synchronized @Nullable FoobotJsonData getSensorData(String uuid) throws FoobotApiException {
|
||||||
try {
|
try {
|
||||||
final String url = URL_TO_FETCH_SENSOR_DATA.replace("%uuid%",
|
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);
|
logger.debug("URL = {}", url);
|
||||||
|
|
||||||
return GSON.fromJson(request(url, apiKey), FoobotJsonData.class);
|
return GSON.fromJson(request(url, apiKey), FoobotJsonData.class);
|
||||||
} catch (JsonParseException | UnsupportedEncodingException e) {
|
} catch (JsonParseException e) {
|
||||||
throw new FoobotApiException(0, e.getMessage());
|
throw new FoobotApiException(0, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ package org.openhab.binding.freebox.internal.api;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
|
@ -470,11 +469,7 @@ public class FreeboxApiManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String encodeUrl(String url) throws FreeboxException {
|
private String encodeUrl(String url) throws FreeboxException {
|
||||||
try {
|
return URLEncoder.encode(url, StandardCharsets.UTF_8);
|
||||||
return URLEncoder.encode(url, StandardCharsets.UTF_8.name());
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new FreeboxException("Encoding the URL \"" + url + "\" in UTF-8 failed", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String hmacSha1(String key, String value) throws FreeboxException {
|
public static String hmacSha1(String key, String value) throws FreeboxException {
|
||||||
|
|
|
@ -20,7 +20,6 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
|
@ -29,6 +28,7 @@ import java.net.SocketException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
@ -91,9 +91,6 @@ public class GlobalCacheHandler extends BaseThingHandler {
|
||||||
// IR transaction counter
|
// IR transaction counter
|
||||||
private AtomicInteger irCounter;
|
private AtomicInteger irCounter;
|
||||||
|
|
||||||
// Character set to use for URL encoding & decoding
|
|
||||||
private String CHARSET = "ISO-8859-1";
|
|
||||||
|
|
||||||
public GlobalCacheHandler(@NonNull Thing gcDevice, String ipv4Address) {
|
public GlobalCacheHandler(@NonNull Thing gcDevice, String ipv4Address) {
|
||||||
super(gcDevice);
|
super(gcDevice);
|
||||||
irCounter = new AtomicInteger(1);
|
irCounter = new AtomicInteger(1);
|
||||||
|
@ -578,7 +575,8 @@ public class GlobalCacheHandler extends BaseThingHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] deviceCommand;
|
byte[] deviceCommand;
|
||||||
deviceCommand = URLDecoder.decode(requestMessage.getDeviceCommand(), CHARSET).getBytes(CHARSET);
|
deviceCommand = URLDecoder.decode(requestMessage.getDeviceCommand(), StandardCharsets.ISO_8859_1)
|
||||||
|
.getBytes(StandardCharsets.ISO_8859_1);
|
||||||
|
|
||||||
logger.debug("Writing decoded deviceCommand byte array: {}", getAsHexString(deviceCommand));
|
logger.debug("Writing decoded deviceCommand byte array: {}", getAsHexString(deviceCommand));
|
||||||
out.write(deviceCommand);
|
out.write(deviceCommand);
|
||||||
|
@ -912,14 +910,8 @@ public class GlobalCacheHandler extends BaseThingHandler {
|
||||||
String endOfMessageString = (String) thing.getConfiguration().get(endOfMessageDelimiterConfig);
|
String endOfMessageString = (String) thing.getConfiguration().get(endOfMessageDelimiterConfig);
|
||||||
if (endOfMessageString != null && !endOfMessageString.isEmpty()) {
|
if (endOfMessageString != null && !endOfMessageString.isEmpty()) {
|
||||||
logger.debug("End of message is {} for thing {} {}", endOfMessageString, thingID(), serialDevice);
|
logger.debug("End of message is {} for thing {} {}", endOfMessageString, thingID(), serialDevice);
|
||||||
byte[] endOfMessage;
|
byte[] endOfMessage = URLDecoder.decode(endOfMessageString, StandardCharsets.ISO_8859_1)
|
||||||
try {
|
.getBytes(StandardCharsets.ISO_8859_1);
|
||||||
endOfMessage = URLDecoder.decode(endOfMessageString, CHARSET).getBytes(CHARSET);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.info("Unable to decode end of message delimiter {} for thing {} {}", endOfMessageString,
|
|
||||||
thingID(), serialDevice);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the serial reader using the above end-of-message delimiter
|
// Start the serial reader using the above end-of-message delimiter
|
||||||
SerialPortReader serialPortReader = new SerialPortReader(serialDevice, getSerialIn(serialDevice),
|
SerialPortReader serialPortReader = new SerialPortReader(serialDevice, getSerialIn(serialDevice),
|
||||||
|
@ -1003,9 +995,6 @@ public class GlobalCacheHandler extends BaseThingHandler {
|
||||||
logger.debug("Rcv data from {} at {}:{}: {}", thingID(), getIP(), serialPort,
|
logger.debug("Rcv data from {} at {}:{}: {}", thingID(), getIP(), serialPort,
|
||||||
getAsHexString(buffer));
|
getAsHexString(buffer));
|
||||||
updateFeedbackChannel(buffer);
|
updateFeedbackChannel(buffer);
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.info("Unsupported encoding exception: {}", e.getMessage(), e);
|
|
||||||
continue;
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.debug("Serial Reader got IOException: {}", e.getMessage());
|
logger.debug("Serial Reader got IOException: {}", e.getMessage());
|
||||||
break;
|
break;
|
||||||
|
@ -1071,13 +1060,10 @@ public class GlobalCacheHandler extends BaseThingHandler {
|
||||||
Channel channel = getThing().getChannel(channelId);
|
Channel channel = getThing().getChannel(channelId);
|
||||||
if (channel != null && isLinked(channelId)) {
|
if (channel != null && isLinked(channelId)) {
|
||||||
logger.debug("Updating feedback channel for port {}", serialPort);
|
logger.debug("Updating feedback channel for port {}", serialPort);
|
||||||
try {
|
String encodedReply = URLEncoder.encode(new String(buffer, StandardCharsets.ISO_8859_1),
|
||||||
String encodedReply = URLEncoder.encode(new String(buffer, CHARSET), CHARSET);
|
StandardCharsets.ISO_8859_1);
|
||||||
logger.debug("encodedReply='{}'", encodedReply);
|
logger.debug("encodedReply='{}'", encodedReply);
|
||||||
updateState(channel.getUID(), new StringType(encodedReply));
|
updateState(channel.getUID(), new StringType(encodedReply));
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.warn("Exception while encoding data read from serial device: {}", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
package org.openhab.binding.groheondus.internal;
|
package org.openhab.binding.groheondus.internal;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -55,8 +54,8 @@ public class AccountServlet extends HttpServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String servletUrl() throws UnsupportedEncodingException {
|
private String servletUrl() {
|
||||||
return "/groheondus/" + URLEncoder.encode(bridgeId, StandardCharsets.UTF_8.name());
|
return "/groheondus/" + URLEncoder.encode(bridgeId, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -130,10 +129,6 @@ public class AccountServlet extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
try {
|
httpService.unregister(servletUrl());
|
||||||
httpService.unregister(servletUrl());
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.warn("Unregistration of servlet failed", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ package org.openhab.binding.haassohnpelletstove.internal;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
@ -115,16 +115,12 @@ public class HaasSohnpelletstoveJSONCommunication {
|
||||||
|
|
||||||
if (postData != null) {
|
if (postData != null) {
|
||||||
try {
|
try {
|
||||||
InputStream targetStream = new ByteArrayInputStream(postData.getBytes("UTF-8"));
|
InputStream targetStream = new ByteArrayInputStream(postData.getBytes(StandardCharsets.UTF_8));
|
||||||
refreshOvenConnection(helper, thingUID);
|
refreshOvenConnection(helper, thingUID);
|
||||||
httpHeader = createHeader(postData);
|
httpHeader = createHeader(postData);
|
||||||
response = HttpUtil.executeUrl("POST", urlStr, httpHeader, targetStream, "application/json", 10000);
|
response = HttpUtil.executeUrl("POST", urlStr, httpHeader, targetStream, "application/json", 10000);
|
||||||
resultOk = true;
|
resultOk = true;
|
||||||
logger.debug("Execute POST request with content to {} with header: {}", urlStr, httpHeader.toString());
|
logger.debug("Execute POST request with content to {} with header: {}", urlStr, httpHeader.toString());
|
||||||
} catch (UnsupportedEncodingException e1) {
|
|
||||||
logger.debug("Wrong encoding found. Only UTF-8 is supported.");
|
|
||||||
statusDescr = "Encoding of oven is not supported. Only UTF-8 is supported.";
|
|
||||||
resultOk = false;
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.debug("Error processiong POST request {}", urlStr);
|
logger.debug("Error processiong POST request {}", urlStr);
|
||||||
statusDescr = "Cannot execute command on Stove. Please verify connection and Thing Status";
|
statusDescr = "Cannot execute command on Stove. Please verify connection and Thing Status";
|
||||||
|
@ -161,9 +157,8 @@ public class HaasSohnpelletstoveJSONCommunication {
|
||||||
* Creates the header for the Post Request
|
* Creates the header for the Post Request
|
||||||
*
|
*
|
||||||
* @return The created Header Properties
|
* @return The created Header Properties
|
||||||
* @throws UnsupportedEncodingException
|
|
||||||
*/
|
*/
|
||||||
private Properties createHeader(@Nullable String postData) throws UnsupportedEncodingException {
|
private Properties createHeader(@Nullable String postData) {
|
||||||
Properties httpHeader = new Properties();
|
Properties httpHeader = new Properties();
|
||||||
httpHeader.setProperty("Host", config.hostIP);
|
httpHeader.setProperty("Host", config.hostIP);
|
||||||
httpHeader.setProperty("Accept", "*/*");
|
httpHeader.setProperty("Accept", "*/*");
|
||||||
|
@ -174,7 +169,7 @@ public class HaasSohnpelletstoveJSONCommunication {
|
||||||
httpHeader.setProperty("token", "32 bytes");
|
httpHeader.setProperty("token", "32 bytes");
|
||||||
httpHeader.setProperty("Content-Type", "application/json");
|
httpHeader.setProperty("Content-Type", "application/json");
|
||||||
if (postData != null) {
|
if (postData != null) {
|
||||||
int a = postData.getBytes("UTF-8").length;
|
int a = postData.getBytes(StandardCharsets.UTF_8).length;
|
||||||
httpHeader.setProperty(xhspin, Integer.toString(a));
|
httpHeader.setProperty(xhspin, Integer.toString(a));
|
||||||
}
|
}
|
||||||
httpHeader.setProperty("User-Agent", "ios");
|
httpHeader.setProperty("User-Agent", "ios");
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.hccrubbishcollection.internal;
|
package org.openhab.binding.hccrubbishcollection.internal;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
@ -60,7 +59,7 @@ public class API {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new API class.
|
* Create a new API class.
|
||||||
*
|
*
|
||||||
* @param httpClient The common http client provided from openHAB.
|
* @param httpClient The common http client provided from openHAB.
|
||||||
* @param address The address of the premises.
|
* @param address The address of the premises.
|
||||||
*/
|
*/
|
||||||
|
@ -71,12 +70,12 @@ public class API {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects to the web service and gets the data.
|
* Connects to the web service and gets the data.
|
||||||
*
|
*
|
||||||
* @return boolean Success.
|
* @return boolean Success.
|
||||||
*/
|
*/
|
||||||
public boolean update() {
|
public boolean update() {
|
||||||
try {
|
try {
|
||||||
final String url = REQUEST_URL + URLEncoder.encode(address, StandardCharsets.UTF_8.toString());
|
final String url = REQUEST_URL + URLEncoder.encode(address, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
logger.debug("Fetching data from URL {} (address hidden)", REQUEST_URL);
|
logger.debug("Fetching data from URL {} (address hidden)", REQUEST_URL);
|
||||||
|
|
||||||
|
@ -131,10 +130,6 @@ public class API {
|
||||||
errorDetailMessage = "HTTP Code " + response.getStatus();
|
errorDetailMessage = "HTTP Code " + response.getStatus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (UnsupportedEncodingException ue) {
|
|
||||||
errorDetail = ThingStatusDetail.COMMUNICATION_ERROR;
|
|
||||||
errorDetailMessage = "Encoding not supported!";
|
|
||||||
return false;
|
|
||||||
} catch (TimeoutException to) {
|
} catch (TimeoutException to) {
|
||||||
errorDetail = ThingStatusDetail.COMMUNICATION_ERROR;
|
errorDetail = ThingStatusDetail.COMMUNICATION_ERROR;
|
||||||
errorDetailMessage = "Response Timeout (will try again soon)";
|
errorDetailMessage = "Response Timeout (will try again soon)";
|
||||||
|
@ -146,7 +141,7 @@ public class API {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the last request status.
|
* Returns the last request status.
|
||||||
*
|
*
|
||||||
* @return ThingStatusDetail The openHAB error type.
|
* @return ThingStatusDetail The openHAB error type.
|
||||||
*/
|
*/
|
||||||
public ThingStatusDetail getErrorDetail() {
|
public ThingStatusDetail getErrorDetail() {
|
||||||
|
@ -155,7 +150,7 @@ public class API {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the error, if occurred.
|
* Gets the error, if occurred.
|
||||||
*
|
*
|
||||||
* @return String The error message.
|
* @return String The error message.
|
||||||
*/
|
*/
|
||||||
public String getErrorDetailMessage() {
|
public String getErrorDetailMessage() {
|
||||||
|
@ -164,7 +159,7 @@ public class API {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The collection week.
|
* The collection week.
|
||||||
*
|
*
|
||||||
* @return Integer The week number.
|
* @return Integer The week number.
|
||||||
*/
|
*/
|
||||||
public @Nullable Integer getCollectionWeek() {
|
public @Nullable Integer getCollectionWeek() {
|
||||||
|
@ -173,7 +168,7 @@ public class API {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the collection day of week.
|
* Gets the collection day of week.
|
||||||
*
|
*
|
||||||
* @return Integer The day of the week. 1 = Monday.
|
* @return Integer The day of the week. 1 = Monday.
|
||||||
*/
|
*/
|
||||||
public @Nullable Integer getDay() {
|
public @Nullable Integer getDay() {
|
||||||
|
@ -182,7 +177,7 @@ public class API {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The upcoming recycling collection date.
|
* The upcoming recycling collection date.
|
||||||
*
|
*
|
||||||
* @return ZonedDateTime
|
* @return ZonedDateTime
|
||||||
*/
|
*/
|
||||||
public @Nullable ZonedDateTime getRecyclingDate() {
|
public @Nullable ZonedDateTime getRecyclingDate() {
|
||||||
|
@ -191,7 +186,7 @@ public class API {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The upcoming general rubbish collection date.
|
* The upcoming general rubbish collection date.
|
||||||
*
|
*
|
||||||
* @return ZonedDateTime
|
* @return ZonedDateTime
|
||||||
*/
|
*/
|
||||||
public @Nullable ZonedDateTime getGeneralDate() {
|
public @Nullable ZonedDateTime getGeneralDate() {
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.heos.internal.json;
|
package org.openhab.binding.heos.internal.json;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -90,10 +89,6 @@ public class HeosJsonParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String decode(String encoded) {
|
private static String decode(String encoded) {
|
||||||
try {
|
return URLDecoder.decode(encoded, StandardCharsets.UTF_8);
|
||||||
return URLDecoder.decode(encoded, StandardCharsets.UTF_8.name());
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new IllegalStateException("Impossible: UTF-8 is a required encoding", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.heos.internal.resources;
|
package org.openhab.binding.heos.internal.resources;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
@ -322,12 +321,8 @@ public class HeosCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String urlEncode(String username) {
|
private static String urlEncode(String username) {
|
||||||
try {
|
String encoded = URLEncoder.encode(username, StandardCharsets.UTF_8);
|
||||||
String encoded = URLEncoder.encode(username, StandardCharsets.UTF_8.toString());
|
// however it cannot handle escaped @ signs
|
||||||
// however it cannot handle escaped @ signs
|
return encoded.replace("%40", "@");
|
||||||
return encoded.replace("%40", "@");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new IllegalStateException("UTF-8 is not supported, bailing out");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.homematic.internal.common;
|
package org.openhab.binding.homematic.internal.common;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.openhab.binding.homematic.internal.model.HmChannel;
|
import org.openhab.binding.homematic.internal.model.HmChannel;
|
||||||
import org.openhab.binding.homematic.internal.model.HmGatewayInfo;
|
import org.openhab.binding.homematic.internal.model.HmGatewayInfo;
|
||||||
import org.openhab.binding.homematic.internal.model.HmInterface;
|
import org.openhab.binding.homematic.internal.model.HmInterface;
|
||||||
|
@ -22,9 +25,6 @@ import org.openhab.binding.homematic.internal.model.HmInterface;
|
||||||
* @author Gerhard Riegler - Initial contribution
|
* @author Gerhard Riegler - Initial contribution
|
||||||
*/
|
*/
|
||||||
public class HomematicConfig {
|
public class HomematicConfig {
|
||||||
private static final String ISO_ENCODING = "ISO-8859-1";
|
|
||||||
private static final String UTF_ENCODING = "UTF-8";
|
|
||||||
|
|
||||||
private static final String GATEWAY_TYPE_AUTO = "AUTO";
|
private static final String GATEWAY_TYPE_AUTO = "AUTO";
|
||||||
private static final String GATEWAY_TYPE_CCU = "CCU";
|
private static final String GATEWAY_TYPE_CCU = "CCU";
|
||||||
private static final String GATEWAY_TYPE_NOCCU = "NOCCU";
|
private static final String GATEWAY_TYPE_NOCCU = "NOCCU";
|
||||||
|
@ -363,11 +363,11 @@ public class HomematicConfig {
|
||||||
/**
|
/**
|
||||||
* Returns the encoding that is suitable on requests to & responds from the Homematic gateway.
|
* Returns the encoding that is suitable on requests to & responds from the Homematic gateway.
|
||||||
*/
|
*/
|
||||||
public String getEncoding() {
|
public Charset getEncoding() {
|
||||||
if (gatewayInfo != null && gatewayInfo.isHomegear()) {
|
if (gatewayInfo != null && gatewayInfo.isHomegear()) {
|
||||||
return UTF_ENCODING;
|
return StandardCharsets.UTF_8;
|
||||||
} else {
|
} else {
|
||||||
return ISO_ENCODING;
|
return StandardCharsets.ISO_8859_1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.io.UnsupportedEncodingException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -52,16 +53,16 @@ public class BinRpcMessage implements RpcRequest<byte[]>, RpcResponse {
|
||||||
private String methodName;
|
private String methodName;
|
||||||
private TYPE type;
|
private TYPE type;
|
||||||
private int args;
|
private int args;
|
||||||
private String encoding;
|
private Charset encoding;
|
||||||
|
|
||||||
public BinRpcMessage(String methodName, String encoding) {
|
public BinRpcMessage(String methodName, Charset encoding) {
|
||||||
this(methodName, TYPE.REQUEST, encoding);
|
this(methodName, TYPE.REQUEST, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new request with the specified methodName.
|
* Creates a new request with the specified methodName.
|
||||||
*/
|
*/
|
||||||
public BinRpcMessage(String methodName, TYPE type, String encoding) {
|
public BinRpcMessage(String methodName, TYPE type, Charset encoding) {
|
||||||
this.methodName = methodName;
|
this.methodName = methodName;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.encoding = encoding;
|
this.encoding = encoding;
|
||||||
|
@ -71,7 +72,7 @@ public class BinRpcMessage implements RpcRequest<byte[]>, RpcResponse {
|
||||||
/**
|
/**
|
||||||
* Decodes a BIN-RPC message from the given InputStream.
|
* Decodes a BIN-RPC message from the given InputStream.
|
||||||
*/
|
*/
|
||||||
public BinRpcMessage(InputStream is, boolean methodHeader, String encoding) throws IOException {
|
public BinRpcMessage(InputStream is, boolean methodHeader, Charset encoding) throws IOException {
|
||||||
this.encoding = encoding;
|
this.encoding = encoding;
|
||||||
byte sig[] = new byte[8];
|
byte sig[] = new byte[8];
|
||||||
int length = is.read(sig, 0, 4);
|
int length = is.read(sig, 0, 4);
|
||||||
|
@ -111,7 +112,7 @@ public class BinRpcMessage implements RpcRequest<byte[]>, RpcResponse {
|
||||||
/**
|
/**
|
||||||
* Decodes a BIN-RPC message from the given byte array.
|
* Decodes a BIN-RPC message from the given byte array.
|
||||||
*/
|
*/
|
||||||
public BinRpcMessage(byte[] message, boolean methodHeader, String encoding) throws IOException, ParseException {
|
public BinRpcMessage(byte[] message, boolean methodHeader, Charset encoding) throws IOException, ParseException {
|
||||||
this.encoding = encoding;
|
this.encoding = encoding;
|
||||||
if (message.length < 8) {
|
if (message.length < 8) {
|
||||||
throw new EOFException("Only " + message.length + " bytes received");
|
throw new EOFException("Only " + message.length + " bytes received");
|
||||||
|
@ -213,7 +214,7 @@ public class BinRpcMessage implements RpcRequest<byte[]>, RpcResponse {
|
||||||
return (new BigInteger(bi)).longValue();
|
return (new BigInteger(bi)).longValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String readString() throws UnsupportedEncodingException {
|
private String readString() {
|
||||||
int len = readInt();
|
int len = readInt();
|
||||||
offset += len;
|
offset += len;
|
||||||
return new String(binRpcData, offset - len, len, encoding);
|
return new String(binRpcData, offset - len, len, encoding);
|
||||||
|
@ -310,12 +311,7 @@ public class BinRpcMessage implements RpcRequest<byte[]>, RpcResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addString(String string) {
|
private void addString(String string) {
|
||||||
byte sd[];
|
byte sd[] = string.getBytes(encoding);
|
||||||
try {
|
|
||||||
sd = string.getBytes(encoding);
|
|
||||||
} catch (UnsupportedEncodingException use) {
|
|
||||||
sd = string.getBytes();
|
|
||||||
}
|
|
||||||
for (byte ch : sd) {
|
for (byte ch : sd) {
|
||||||
addByte(ch);
|
addByte(ch);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ package org.openhab.binding.homematic.internal.communicator.message;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
@ -43,7 +44,7 @@ public class XmlRpcResponse implements RpcResponse {
|
||||||
/**
|
/**
|
||||||
* Decodes a XML-RPC message from the given InputStream.
|
* Decodes a XML-RPC message from the given InputStream.
|
||||||
*/
|
*/
|
||||||
public XmlRpcResponse(InputStream is, String encoding)
|
public XmlRpcResponse(InputStream is, Charset encoding)
|
||||||
throws SAXException, ParserConfigurationException, IOException {
|
throws SAXException, ParserConfigurationException, IOException {
|
||||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||||
SAXParser saxParser = factory.newSAXParser();
|
SAXParser saxParser = factory.newSAXParser();
|
||||||
|
@ -51,7 +52,7 @@ public class XmlRpcResponse implements RpcResponse {
|
||||||
saxParser.getXMLReader().setFeature("http://xml.org/sax/features/external-general-entities", false);
|
saxParser.getXMLReader().setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||||
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||||
InputSource inputSource = new InputSource(is);
|
InputSource inputSource = new InputSource(is);
|
||||||
inputSource.setEncoding(encoding);
|
inputSource.setEncoding(encoding.name());
|
||||||
saxParser.parse(inputSource, new XmlRpcHandler());
|
saxParser.parse(inputSource, new XmlRpcHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,11 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.ihc.internal.ws;
|
package org.openhab.binding.ihc.internal.ws;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -57,10 +57,10 @@ public class IhcClientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loadProjectFileFromControllerTest() throws IhcExecption, UnsupportedEncodingException {
|
public void loadProjectFileFromControllerTest() throws IhcExecption {
|
||||||
final String expectedFileContent = ResourceFileUtils.getFileContent("ProjectFileContent.txt");
|
final String expectedFileContent = ResourceFileUtils.getFileContent("ProjectFileContent.txt");
|
||||||
|
|
||||||
final byte[] result = ihcClient.getProjectFileFromController();
|
final byte[] result = ihcClient.getProjectFileFromController();
|
||||||
assertEquals(expectedFileContent, new String(result, "UTF-8"));
|
assertEquals(expectedFileContent, new String(result, StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,11 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.ipcamera.internal;
|
package org.openhab.binding.ipcamera.internal;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
@ -111,12 +111,7 @@ public class Helper {
|
||||||
* @author Matthew Skinner - Initial contribution
|
* @author Matthew Skinner - Initial contribution
|
||||||
*/
|
*/
|
||||||
public static String encodeSpecialChars(String text) {
|
public static String encodeSpecialChars(String text) {
|
||||||
String processed = text;
|
return URLEncoder.encode(text, StandardCharsets.UTF_8).replace("+", "%20");
|
||||||
try {
|
|
||||||
processed = URLEncoder.encode(text, "UTF-8").replace("+", "%20");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
}
|
|
||||||
return processed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLocalIpAddress() {
|
public static String getLocalIpAddress() {
|
||||||
|
|
|
@ -14,7 +14,6 @@ package org.openhab.binding.ipcamera.internal.onvif;
|
||||||
|
|
||||||
import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.*;
|
import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
|
@ -503,10 +502,9 @@ public class OnvifConnection {
|
||||||
try {
|
try {
|
||||||
msgDigest = MessageDigest.getInstance("SHA-1");
|
msgDigest = MessageDigest.getInstance("SHA-1");
|
||||||
msgDigest.reset();
|
msgDigest.reset();
|
||||||
msgDigest.update(beforeEncryption.getBytes("utf8"));
|
msgDigest.update(beforeEncryption.getBytes(StandardCharsets.UTF_8));
|
||||||
encryptedRaw = msgDigest.digest();
|
encryptedRaw = msgDigest.digest();
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
}
|
}
|
||||||
return Base64.getEncoder().encodeToString(encryptedRaw);
|
return Base64.getEncoder().encodeToString(encryptedRaw);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
package org.openhab.binding.kodi.internal.protocol;
|
package org.openhab.binding.kodi.internal.protocol;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
@ -857,16 +856,11 @@ public class KodiConnection implements KodiClientSocketEventListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable String stripImageUrl(String url) {
|
private @Nullable String stripImageUrl(String url) {
|
||||||
try {
|
// we have to strip ending "/" here because Kodi returns a not valid path and filename
|
||||||
// we have to strip ending "/" here because Kodi returns a not valid path and filename
|
// "fanart":"image://http%3a%2f%2fthetvdb.com%2fbanners%2ffanart%2foriginal%2f263365-31.jpg/"
|
||||||
// "fanart":"image://http%3a%2f%2fthetvdb.com%2fbanners%2ffanart%2foriginal%2f263365-31.jpg/"
|
// "thumbnail":"image://http%3a%2f%2fthetvdb.com%2fbanners%2fepisodes%2f263365%2f5640869.jpg/"
|
||||||
// "thumbnail":"image://http%3a%2f%2fthetvdb.com%2fbanners%2fepisodes%2f263365%2f5640869.jpg/"
|
String encodedURL = URLEncoder.encode(stripEnd(url, '/'), StandardCharsets.UTF_8);
|
||||||
String encodedURL = URLEncoder.encode(stripEnd(url, '/'), StandardCharsets.UTF_8.name());
|
return imageUri.resolve(encodedURL).toString();
|
||||||
return imageUri.resolve(encodedURL).toString();
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.debug("exception during encoding {}", url, e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String stripEnd(final String str, final char suffix) {
|
private String stripEnd(final String str, final char suffix) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ package org.openhab.binding.kostalinverter.internal.thirdgeneration;
|
||||||
|
|
||||||
import static org.openhab.binding.kostalinverter.internal.thirdgeneration.ThirdGenerationBindingConstants.*;
|
import static org.openhab.binding.kostalinverter.internal.thirdgeneration.ThirdGenerationBindingConstants.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
@ -443,8 +443,8 @@ public class ThirdGenerationHandler extends BaseThingHandler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
data = cipher.doFinal(token.getBytes("UTF-8"));
|
data = cipher.doFinal(token.getBytes(StandardCharsets.UTF_8));
|
||||||
} catch (IllegalBlockSizeException | BadPaddingException | UnsupportedEncodingException e1) {
|
} catch (IllegalBlockSizeException | BadPaddingException e1) {
|
||||||
// No JSON answer received
|
// No JSON answer received
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, COMMUNICATION_ERROR_JSON);
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, COMMUNICATION_ERROR_JSON);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.loxone.internal.security;
|
package org.openhab.binding.loxone.internal.security;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
|
@ -238,11 +237,7 @@ class LxWsSecurityToken extends LxWsSecurity {
|
||||||
try {
|
try {
|
||||||
String encrypted = Base64.getEncoder()
|
String encrypted = Base64.getEncoder()
|
||||||
.encodeToString(aesEncryptCipher.doFinal(str.getBytes(StandardCharsets.UTF_8)));
|
.encodeToString(aesEncryptCipher.doFinal(str.getBytes(StandardCharsets.UTF_8)));
|
||||||
try {
|
encrypted = URLEncoder.encode(encrypted, StandardCharsets.UTF_8);
|
||||||
encrypted = URLEncoder.encode(encrypted, "UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.warn("[{}] Unsupported encoding for encrypted command conversion to URL.", debugId);
|
|
||||||
}
|
|
||||||
return CMD_ENCRYPT_CMD + encrypted;
|
return CMD_ENCRYPT_CMD + encrypted;
|
||||||
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
||||||
logger.warn("[{}] Command encryption failed: {}", debugId, e.getMessage());
|
logger.warn("[{}] Command encryption failed: {}", debugId, e.getMessage());
|
||||||
|
@ -260,7 +255,7 @@ class LxWsSecurityToken extends LxWsSecurity {
|
||||||
try {
|
try {
|
||||||
byte[] bytes = Base64.getDecoder().decode(string);
|
byte[] bytes = Base64.getDecoder().decode(string);
|
||||||
bytes = aesDecryptCipher.doFinal(bytes);
|
bytes = aesDecryptCipher.doFinal(bytes);
|
||||||
string = new String(bytes, "UTF-8");
|
string = new String(bytes, StandardCharsets.UTF_8);
|
||||||
string = string.replaceAll("\0+.*$", "");
|
string = string.replaceAll("\0+.*$", "");
|
||||||
string = string.replaceFirst("^salt/[^/]*/", "");
|
string = string.replaceFirst("^salt/[^/]*/", "");
|
||||||
string = string.replaceFirst("^nextSalt/[^/]*/[^/]*/", "");
|
string = string.replaceFirst("^nextSalt/[^/]*/[^/]*/", "");
|
||||||
|
@ -269,8 +264,6 @@ class LxWsSecurityToken extends LxWsSecurity {
|
||||||
logger.debug("[{}] Failed to decode base64 string: {}", debugId, string);
|
logger.debug("[{}] Failed to decode base64 string: {}", debugId, string);
|
||||||
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
||||||
logger.warn("[{}] Command decryption failed: {}", debugId, e.getMessage());
|
logger.warn("[{}] Command decryption failed: {}", debugId, e.getMessage());
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.warn("[{}] Unsupported encoding for decrypted bytes to string conversion.", debugId);
|
|
||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
@ -544,11 +537,7 @@ class LxWsSecurityToken extends LxWsSecurity {
|
||||||
byte[] bytes = new byte[SALT_BYTES];
|
byte[] bytes = new byte[SALT_BYTES];
|
||||||
secureRandom.nextBytes(bytes);
|
secureRandom.nextBytes(bytes);
|
||||||
String salt = HexUtils.bytesToHex(bytes);
|
String salt = HexUtils.bytesToHex(bytes);
|
||||||
try {
|
salt = URLEncoder.encode(salt, StandardCharsets.UTF_8);
|
||||||
salt = URLEncoder.encode(salt, "UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.warn("[{}] Unsupported encoding for salt conversion to URL.", debugId);
|
|
||||||
}
|
|
||||||
saltTimeStamp = timeElapsedInSeconds();
|
saltTimeStamp = timeElapsedInSeconds();
|
||||||
saltUseCount = 0;
|
saltUseCount = 0;
|
||||||
logger.debug("[{}] Generated salt: {}", debugId, salt);
|
logger.debug("[{}] Generated salt: {}", debugId, salt);
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.magentatv.internal;
|
package org.openhab.binding.magentatv.internal;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -100,8 +99,6 @@ public class MagentaTVBindingConstants {
|
||||||
public static final int DEF_REFRESH_INTERVAL_SEC = 60;
|
public static final int DEF_REFRESH_INTERVAL_SEC = 60;
|
||||||
public static final int NETWORK_TIMEOUT_MS = 3000;
|
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_CONTENT_TYPE = "Content-Type";
|
||||||
public static final String HEADER_HOST = "HOST";
|
public static final String HEADER_HOST = "HOST";
|
||||||
public static final String HEADER_ACCEPT = "Accept";
|
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.MagentaTVBindingConstants.*;
|
||||||
import static org.openhab.binding.magentatv.internal.MagentaTVUtil.*;
|
import static org.openhab.binding.magentatv.internal.MagentaTVUtil.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
@ -480,7 +480,7 @@ public class MagentaTVControl {
|
||||||
*/
|
*/
|
||||||
public static String computeMD5(String unhashed) {
|
public static String computeMD5(String unhashed) {
|
||||||
try {
|
try {
|
||||||
byte[] bytesOfMessage = unhashed.getBytes(UTF_8);
|
byte[] bytesOfMessage = unhashed.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
MessageDigest md5 = MessageDigest.getInstance(HASH_ALGORITHM_MD5);
|
MessageDigest md5 = MessageDigest.getInstance(HASH_ALGORITHM_MD5);
|
||||||
byte[] hash = md5.digest(bytesOfMessage);
|
byte[] hash = md5.digest(bytesOfMessage);
|
||||||
|
@ -490,7 +490,7 @@ public class MagentaTVControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import static org.openhab.binding.magentatv.internal.MagentaTVBindingConstants.*
|
||||||
import static org.openhab.binding.magentatv.internal.MagentaTVUtil.substringBetween;
|
import static org.openhab.binding.magentatv.internal.MagentaTVUtil.substringBetween;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
@ -139,7 +140,7 @@ public class MagentaTVNotifyServlet extends HttpServlet {
|
||||||
} finally {
|
} finally {
|
||||||
// send response
|
// send response
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
response.setCharacterEncoding(UTF_8);
|
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||||
response.getWriter().write("");
|
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.MagentaTVBindingConstants.*;
|
||||||
import static org.openhab.binding.magentatv.internal.MagentaTVUtil.*;
|
import static org.openhab.binding.magentatv.internal.MagentaTVUtil.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.HttpCookie;
|
import java.net.HttpCookie;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
@ -291,11 +290,6 @@ public class MagentaTVOAuth {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String urlEncode(String url) {
|
private String urlEncode(String url) {
|
||||||
try {
|
return URLEncoder.encode(url, StandardCharsets.UTF_8);
|
||||||
return URLEncoder.encode(url, UTF_8);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.warn("OAuth: Unable to URL encode string {}", url, e);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.mihome.internal;
|
package org.openhab.binding.mihome.internal;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
@ -55,13 +55,7 @@ public class EncryptionHelper {
|
||||||
logger.warn("Failed to construct Cipher");
|
logger.warn("Failed to construct Cipher");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
SecretKeySpec keySpec;
|
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
|
||||||
try {
|
|
||||||
keySpec = new SecretKeySpec(key.getBytes("UTF8"), "AES");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.warn("Failed to construct SecretKeySpec");
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, keySpec, vector);
|
cipher.init(Cipher.ENCRYPT_MODE, keySpec, vector);
|
||||||
} catch (InvalidKeyException | InvalidAlgorithmParameterException e) {
|
} catch (InvalidKeyException | InvalidAlgorithmParameterException e) {
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.miio.internal;
|
package org.openhab.binding.miio.internal;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
|
@ -99,11 +99,7 @@ public class MiIoCrypto {
|
||||||
SecretKeySpec keySpec = new SecretKeySpec(new byte[16], "AES");
|
SecretKeySpec keySpec = new SecretKeySpec(new byte[16], "AES");
|
||||||
cipher.init(Cipher.DECRYPT_MODE, keySpec);
|
cipher.init(Cipher.DECRYPT_MODE, keySpec);
|
||||||
byte[] decrypted = cipher.doFinal(cipherText);
|
byte[] decrypted = cipher.doFinal(cipherText);
|
||||||
try {
|
return new String(decrypted, StandardCharsets.UTF_8).trim();
|
||||||
return new String(decrypted, "UTF-8").trim();
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
return new String(decrypted).trim();
|
|
||||||
}
|
|
||||||
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException
|
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException
|
||||||
| BadPaddingException e) {
|
| BadPaddingException e) {
|
||||||
throw new MiIoCryptoException(e.getMessage(), e);
|
throw new MiIoCryptoException(e.getMessage(), e);
|
||||||
|
|
|
@ -15,11 +15,11 @@ package org.openhab.binding.myq.internal.handler;
|
||||||
import static org.openhab.binding.myq.internal.MyQBindingConstants.*;
|
import static org.openhab.binding.myq.internal.MyQBindingConstants.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.CookieStore;
|
import java.net.CookieStore;
|
||||||
import java.net.HttpCookie;
|
import java.net.HttpCookie;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
@ -485,7 +485,7 @@ public class MyQAccountHandler extends BaseBridgeHandler implements AccessTokenR
|
||||||
ContentResponse response = request.send();
|
ContentResponse response = request.send();
|
||||||
logger.debug("Login Code {} Response {}", response.getStatus(), response.getContentAsString());
|
logger.debug("Login Code {} Response {}", response.getStatus(), response.getContentAsString());
|
||||||
return response;
|
return response;
|
||||||
} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
throw new ExecutionException(e.getCause());
|
throw new ExecutionException(e.getCause());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -613,16 +613,15 @@ public class MyQAccountHandler extends BaseBridgeHandler implements AccessTokenR
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateCodeVerifier() throws UnsupportedEncodingException {
|
private String generateCodeVerifier() {
|
||||||
SecureRandom secureRandom = new SecureRandom();
|
SecureRandom secureRandom = new SecureRandom();
|
||||||
byte[] codeVerifier = new byte[32];
|
byte[] codeVerifier = new byte[32];
|
||||||
secureRandom.nextBytes(codeVerifier);
|
secureRandom.nextBytes(codeVerifier);
|
||||||
return Base64.getUrlEncoder().withoutPadding().encodeToString(codeVerifier);
|
return Base64.getUrlEncoder().withoutPadding().encodeToString(codeVerifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateCodeChallange(String codeVerifier)
|
private String generateCodeChallange(String codeVerifier) throws NoSuchAlgorithmException {
|
||||||
throws UnsupportedEncodingException, NoSuchAlgorithmException {
|
byte[] bytes = codeVerifier.getBytes(StandardCharsets.US_ASCII);
|
||||||
byte[] bytes = codeVerifier.getBytes("US-ASCII");
|
|
||||||
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
|
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
|
||||||
messageDigest.update(bytes, 0, bytes.length);
|
messageDigest.update(bytes, 0, bytes.length);
|
||||||
byte[] digest = messageDigest.digest();
|
byte[] digest = messageDigest.digest();
|
||||||
|
|
|
@ -22,7 +22,7 @@ import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
@ -37,12 +37,12 @@ import com.google.gson.stream.JsonWriter;
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class SDMDataUtil {
|
public class SDMDataUtil {
|
||||||
|
|
||||||
public static Reader openDataReader(String fileName) throws UnsupportedEncodingException, FileNotFoundException {
|
public static Reader openDataReader(String fileName) throws FileNotFoundException {
|
||||||
String packagePath = (SDMDataUtil.class.getPackage().getName()).replaceAll("\\.", "/");
|
String packagePath = (SDMDataUtil.class.getPackage().getName()).replaceAll("\\.", "/");
|
||||||
String filePath = "src/test/resources/" + packagePath + "/" + fileName;
|
String filePath = "src/test/resources/" + packagePath + "/" + fileName;
|
||||||
|
|
||||||
InputStream inputStream = new FileInputStream(filePath);
|
InputStream inputStream = new FileInputStream(filePath);
|
||||||
return new InputStreamReader(inputStream, "UTF-8");
|
return new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T fromJson(String fileName, Class<T> dataClass) throws IOException {
|
public static <T> T fromJson(String fileName, Class<T> dataClass) throws IOException {
|
||||||
|
|
|
@ -14,7 +14,6 @@ package org.openhab.binding.nibeuplink.internal.connector;
|
||||||
|
|
||||||
import static org.openhab.binding.nibeuplink.internal.NibeUplinkBindingConstants.*;
|
import static org.openhab.binding.nibeuplink.internal.NibeUplinkBindingConstants.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
@ -200,8 +199,6 @@ public class UplinkWebInterface implements AtomicReferenceTrait {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* authenticates with the Nibe Uplink WEB interface
|
* authenticates with the Nibe Uplink WEB interface
|
||||||
*
|
|
||||||
* @throws UnsupportedEncodingException
|
|
||||||
*/
|
*/
|
||||||
private synchronized void authenticate() {
|
private synchronized void authenticate() {
|
||||||
setAuthenticated(false);
|
setAuthenticated(false);
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.powermax.internal.state;
|
package org.openhab.binding.powermax.internal.state;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
@ -364,11 +364,7 @@ public class PowermaxPanelSettings {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if ((data[i] & 0x000000FF) >= 0x20) {
|
if ((data[i] & 0x000000FF) >= 0x20) {
|
||||||
try {
|
result += new String(data, i, 1, StandardCharsets.US_ASCII);
|
||||||
result += new String(data, i, 1, "US-ASCII");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.debug("Unhandled character code {}", data[i]);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logger.debug("Unhandled character code {}", data[i]);
|
logger.debug("Unhandled character code {}", data[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
package org.openhab.binding.radiothermostat.internal.discovery;
|
package org.openhab.binding.radiothermostat.internal.discovery;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
@ -57,7 +56,6 @@ import com.google.gson.JsonSyntaxException;
|
||||||
* @author Michael Lobstein - Cleanup for RadioThermostat
|
* @author Michael Lobstein - Cleanup for RadioThermostat
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
@Component(service = DiscoveryService.class, configurationPid = "discovery.radiothermostat")
|
@Component(service = DiscoveryService.class, configurationPid = "discovery.radiothermostat")
|
||||||
public class RadioThermostatDiscoveryService extends AbstractDiscoveryService {
|
public class RadioThermostatDiscoveryService extends AbstractDiscoveryService {
|
||||||
|
@ -119,10 +117,8 @@ public class RadioThermostatDiscoveryService extends AbstractDiscoveryService {
|
||||||
* @throws UnknownHostException
|
* @throws UnknownHostException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws SocketException
|
* @throws SocketException
|
||||||
* @throws UnsupportedEncodingException
|
|
||||||
*/
|
*/
|
||||||
private void sendDiscoveryBroacast(NetworkInterface ni)
|
private void sendDiscoveryBroacast(NetworkInterface ni) throws UnknownHostException, SocketException {
|
||||||
throws UnknownHostException, SocketException, UnsupportedEncodingException {
|
|
||||||
InetAddress m = InetAddress.getByName("239.255.255.250");
|
InetAddress m = InetAddress.getByName("239.255.255.250");
|
||||||
final int port = 1900;
|
final int port = 1900;
|
||||||
logger.debug("Sending discovery broadcast");
|
logger.debug("Sending discovery broadcast");
|
||||||
|
@ -153,7 +149,7 @@ public class RadioThermostatDiscoveryService extends AbstractDiscoveryService {
|
||||||
socket.setNetworkInterface(ni);
|
socket.setNetworkInterface(ni);
|
||||||
socket.joinGroup(m);
|
socket.joinGroup(m);
|
||||||
logger.debug("Joined UPnP Multicast group on Interface: {}", ni.getName());
|
logger.debug("Joined UPnP Multicast group on Interface: {}", ni.getName());
|
||||||
byte[] requestMessage = RADIOTHERMOSTAT_DISCOVERY_MESSAGE.getBytes("UTF-8");
|
byte[] requestMessage = RADIOTHERMOSTAT_DISCOVERY_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||||
DatagramPacket datagramPacket = new DatagramPacket(requestMessage, requestMessage.length, m, port);
|
DatagramPacket datagramPacket = new DatagramPacket(requestMessage, requestMessage.length, m, port);
|
||||||
socket.send(datagramPacket);
|
socket.send(datagramPacket);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.robonect.internal.model.cmd;
|
package org.openhab.binding.robonect.internal.model.cmd;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
@ -22,7 +21,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The command allows to set or retrieve the mower name.
|
* The command allows to set or retrieve the mower name.
|
||||||
*
|
*
|
||||||
* @author Marco Meyer - Initial contribution
|
* @author Marco Meyer - Initial contribution
|
||||||
*/
|
*/
|
||||||
public class NameCommand implements Command {
|
public class NameCommand implements Command {
|
||||||
|
@ -33,7 +32,7 @@ public class NameCommand implements Command {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets the mower name.
|
* sets the mower name.
|
||||||
*
|
*
|
||||||
* @param newName - the mower name.
|
* @param newName - the mower name.
|
||||||
* @return - the command instance.
|
* @return - the command instance.
|
||||||
*/
|
*/
|
||||||
|
@ -52,13 +51,7 @@ public class NameCommand implements Command {
|
||||||
if (newName == null) {
|
if (newName == null) {
|
||||||
return baseURL + "?cmd=name";
|
return baseURL + "?cmd=name";
|
||||||
} else {
|
} else {
|
||||||
try {
|
return baseURL + "?cmd=name&name=" + URLEncoder.encode(newName, StandardCharsets.ISO_8859_1);
|
||||||
return baseURL + "?cmd=name&name="
|
|
||||||
+ URLEncoder.encode(newName, StandardCharsets.ISO_8859_1.displayName());
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.error("Could not encode name {} ", newName, e);
|
|
||||||
return baseURL + "?cmd=name";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ package org.openhab.binding.shelly.internal.util;
|
||||||
|
|
||||||
import static org.openhab.binding.shelly.internal.ShellyBindingConstants.*;
|
import static org.openhab.binding.shelly.internal.ShellyBindingConstants.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
@ -271,11 +270,7 @@ public class ShellyUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String urlEncode(String input) {
|
public static String urlEncode(String input) {
|
||||||
try {
|
return URLEncoder.encode(input, StandardCharsets.UTF_8);
|
||||||
return URLEncoder.encode(input, StandardCharsets.UTF_8.toString());
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Long now() {
|
public static Long now() {
|
||||||
|
|
|
@ -20,7 +20,6 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.ProtocolException;
|
import java.net.ProtocolException;
|
||||||
|
@ -129,8 +128,7 @@ public class RdsDataPoints {
|
||||||
* private method: execute an HTTP PUT on the server to set a data point value
|
* private method: execute an HTTP PUT on the server to set a data point value
|
||||||
*/
|
*/
|
||||||
private void httpSetPointValueJson(String apiKey, String token, String pointUrl, String json)
|
private void httpSetPointValueJson(String apiKey, String token, String pointUrl, String json)
|
||||||
throws RdsCloudException, UnsupportedEncodingException, ProtocolException, MalformedURLException,
|
throws RdsCloudException, ProtocolException, MalformedURLException, IOException {
|
||||||
IOException {
|
|
||||||
/*
|
/*
|
||||||
* NOTE: this class uses JAVAX HttpsURLConnection library instead of the
|
* NOTE: this class uses JAVAX HttpsURLConnection library instead of the
|
||||||
* preferred JETTY library; the reason is that JETTY does not allow sending the
|
* preferred JETTY library; the reason is that JETTY does not allow sending the
|
||||||
|
|
|
@ -14,7 +14,6 @@ package org.openhab.binding.solaredge.internal.connector;
|
||||||
|
|
||||||
import static org.openhab.binding.solaredge.internal.SolarEdgeBindingConstants.*;
|
import static org.openhab.binding.solaredge.internal.SolarEdgeBindingConstants.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
@ -193,8 +192,6 @@ public class WebInterface implements AtomicReferenceTrait {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* authenticates with the Solaredge WEB interface
|
* authenticates with the Solaredge WEB interface
|
||||||
*
|
|
||||||
* @throws UnsupportedEncodingException
|
|
||||||
*/
|
*/
|
||||||
private synchronized void authenticate() {
|
private synchronized void authenticate() {
|
||||||
setAuthenticated(false);
|
setAuthenticated(false);
|
||||||
|
|
|
@ -14,7 +14,6 @@ package org.openhab.binding.somfytahoma.internal.handler;
|
||||||
|
|
||||||
import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
|
import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
@ -282,11 +281,7 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String urlEncode(String text) {
|
private String urlEncode(String text) {
|
||||||
try {
|
return URLEncoder.encode(text, StandardCharsets.UTF_8);
|
||||||
return URLEncoder.encode(text, StandardCharsets.UTF_8.toString());
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableLogin() {
|
private void enableLogin() {
|
||||||
|
|
|
@ -19,7 +19,6 @@ import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
@ -91,9 +90,6 @@ public class SqueezeBoxServerHandler extends BaseBridgeHandler {
|
||||||
// time in seconds to try to reconnect
|
// time in seconds to try to reconnect
|
||||||
private static final int RECONNECT_TIME = 60;
|
private static final int RECONNECT_TIME = 60;
|
||||||
|
|
||||||
// utf8 charset name
|
|
||||||
private static final String UTF8_NAME = StandardCharsets.UTF_8.name();
|
|
||||||
|
|
||||||
// the value by which the volume is changed by each INCREASE or
|
// the value by which the volume is changed by each INCREASE or
|
||||||
// DECREASE-Event
|
// DECREASE-Event
|
||||||
private static final int VOLUME_CHANGE_SIZE = 5;
|
private static final int VOLUME_CHANGE_SIZE = 5;
|
||||||
|
@ -520,21 +516,11 @@ public class SqueezeBoxServerHandler extends BaseBridgeHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String decode(String raw) {
|
private String decode(String raw) {
|
||||||
try {
|
return URLDecoder.decode(raw, StandardCharsets.UTF_8);
|
||||||
return URLDecoder.decode(raw, UTF8_NAME);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.debug("Failed to decode '{}' ", raw, e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String encode(String raw) {
|
private String encode(String raw) {
|
||||||
try {
|
return URLEncoder.encode(raw, StandardCharsets.UTF_8);
|
||||||
return URLEncoder.encode(raw, UTF8_NAME);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.debug("Failed to encode '{}' ", raw, e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
|
|
|
@ -14,7 +14,6 @@ package org.openhab.binding.touchwand.internal;
|
||||||
|
|
||||||
import static org.openhab.binding.touchwand.internal.TouchWandBindingConstants.*;
|
import static org.openhab.binding.touchwand.internal.TouchWandBindingConstants.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.CookieManager;
|
import java.net.CookieManager;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -104,18 +103,11 @@ public class TouchWandRestClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final boolean cmdLogin(String user, String pass, String ipAddr) {
|
private final boolean cmdLogin(String user, String pass, String ipAddr) {
|
||||||
String encodedUser;
|
String encodedUser = URLEncoder.encode(user, StandardCharsets.UTF_8);
|
||||||
String encodedPass;
|
String encodedPass = URLEncoder.encode(pass, StandardCharsets.UTF_8);
|
||||||
String response = "";
|
String response = "";
|
||||||
|
String command = buildUrl(CMD_LOGIN) + "user=" + encodedUser + "&" + "psw=" + encodedPass;
|
||||||
try {
|
response = sendCommand(command, METHOD_GET, "");
|
||||||
encodedUser = URLEncoder.encode(user, StandardCharsets.UTF_8.toString());
|
|
||||||
encodedPass = URLEncoder.encode(pass, StandardCharsets.UTF_8.toString());
|
|
||||||
String command = buildUrl(CMD_LOGIN) + "user=" + encodedUser + "&" + "psw=" + encodedPass;
|
|
||||||
response = sendCommand(command, METHOD_GET, "");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.warn("Error url encoding username or password : {}", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return !response.equals("Unauthorized");
|
return !response.equals("Unauthorized");
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ package org.openhab.binding.upnpcontrol.internal.handler;
|
||||||
|
|
||||||
import static org.openhab.binding.upnpcontrol.internal.UpnpControlBindingConstants.*;
|
import static org.openhab.binding.upnpcontrol.internal.UpnpControlBindingConstants.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
@ -411,22 +410,18 @@ public class UpnpRendererHandler extends UpnpHandler {
|
||||||
*/
|
*/
|
||||||
public void setCurrentURI(String URI, String URIMetaData) {
|
public void setCurrentURI(String URI, String URIMetaData) {
|
||||||
String uri = "";
|
String uri = "";
|
||||||
try {
|
uri = URLDecoder.decode(URI.trim(), StandardCharsets.UTF_8);
|
||||||
uri = URLDecoder.decode(URI.trim(), StandardCharsets.UTF_8.name());
|
// Some renderers don't send a URI Last Changed event when the same URI is requested, so don't wait for it
|
||||||
// Some renderers don't send a URI Last Changed event when the same URI is requested, so don't wait for it
|
// before starting to play
|
||||||
// before starting to play
|
if (!uri.equals(nowPlayingUri) && !playingNotification) {
|
||||||
if (!uri.equals(nowPlayingUri) && !playingNotification) {
|
CompletableFuture<Boolean> settingURI = isSettingURI;
|
||||||
CompletableFuture<Boolean> settingURI = isSettingURI;
|
if (settingURI != null) {
|
||||||
if (settingURI != null) {
|
settingURI.complete(false);
|
||||||
settingURI.complete(false);
|
|
||||||
}
|
|
||||||
isSettingURI = new CompletableFuture<Boolean>(); // set this so we don't start playing when not finished
|
|
||||||
// setting URI
|
|
||||||
} else {
|
|
||||||
logger.debug("New URI {} is same as previous on renderer {}", nowPlayingUri, thing.getLabel());
|
|
||||||
}
|
}
|
||||||
} catch (UnsupportedEncodingException ignore) {
|
isSettingURI = new CompletableFuture<Boolean>(); // set this so we don't start playing when not finished
|
||||||
uri = URI;
|
// setting URI
|
||||||
|
} else {
|
||||||
|
logger.debug("New URI {} is same as previous on renderer {}", nowPlayingUri, thing.getLabel());
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> inputs = new HashMap<>();
|
Map<String, String> inputs = new HashMap<>();
|
||||||
|
@ -1244,18 +1239,14 @@ public class UpnpRendererHandler extends UpnpHandler {
|
||||||
String uri = "";
|
String uri = "";
|
||||||
String currentUri = "";
|
String currentUri = "";
|
||||||
String nextUri = "";
|
String nextUri = "";
|
||||||
try {
|
if (value != null) {
|
||||||
if (value != null) {
|
uri = URLDecoder.decode(value.trim(), StandardCharsets.UTF_8);
|
||||||
uri = URLDecoder.decode(value.trim(), StandardCharsets.UTF_8.name());
|
}
|
||||||
}
|
if (current != null) {
|
||||||
if (current != null) {
|
currentUri = URLDecoder.decode(current.getRes().trim(), StandardCharsets.UTF_8);
|
||||||
currentUri = URLDecoder.decode(current.getRes().trim(), StandardCharsets.UTF_8.name());
|
}
|
||||||
}
|
if (next != null) {
|
||||||
if (next != null) {
|
nextUri = URLDecoder.decode(next.getRes(), StandardCharsets.UTF_8);
|
||||||
nextUri = URLDecoder.decode(next.getRes(), StandardCharsets.UTF_8.name());
|
|
||||||
}
|
|
||||||
} catch (UnsupportedEncodingException ignore) {
|
|
||||||
// If not valid current URI, we assume there is none
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playingNotification && uri.equals(notificationUri)) {
|
if (playingNotification && uri.equals(notificationUri)) {
|
||||||
|
@ -1635,15 +1626,9 @@ public class UpnpRendererHandler extends UpnpHandler {
|
||||||
String mediaRes = media.getRes().trim();
|
String mediaRes = media.getRes().trim();
|
||||||
String entryRes = (entry != null) ? entry.getRes().trim() : "";
|
String entryRes = (entry != null) ? entry.getRes().trim() : "";
|
||||||
|
|
||||||
try {
|
String mediaUrl = URLDecoder.decode(mediaRes, StandardCharsets.UTF_8);
|
||||||
String mediaUrl = URLDecoder.decode(mediaRes, StandardCharsets.UTF_8.name());
|
String entryUrl = URLDecoder.decode(entryRes, StandardCharsets.UTF_8);
|
||||||
String entryUrl = URLDecoder.decode(entryRes, StandardCharsets.UTF_8.name());
|
isCurrent = mediaUrl.equals(entryUrl);
|
||||||
isCurrent = mediaUrl.equals(entryUrl);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.debug("Renderer {} unsupported encoding for new {} or current {} res URL, trying string compare",
|
|
||||||
thing.getLabel(), mediaRes, entryRes);
|
|
||||||
isCurrent = mediaRes.equals(entryRes);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.trace("Current queue res: {}", entryRes);
|
logger.trace("Current queue res: {}", entryRes);
|
||||||
logger.trace("Updated media res: {}", mediaRes);
|
logger.trace("Updated media res: {}", mediaRes);
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
package org.openhab.binding.venstarthermostat.internal.discovery;
|
package org.openhab.binding.venstarthermostat.internal.discovery;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
@ -22,6 +21,7 @@ import java.net.MulticastSocket;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
@ -114,10 +114,9 @@ public class VenstarThermostatDiscoveryService extends AbstractDiscoveryService
|
||||||
* @throws UnknownHostException
|
* @throws UnknownHostException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws SocketException
|
* @throws SocketException
|
||||||
* @throws UnsupportedEncodingException
|
|
||||||
*/
|
*/
|
||||||
private @Nullable MulticastSocket sendDiscoveryBroacast(NetworkInterface ni)
|
private @Nullable MulticastSocket sendDiscoveryBroacast(NetworkInterface ni)
|
||||||
throws UnknownHostException, SocketException, UnsupportedEncodingException {
|
throws UnknownHostException, SocketException {
|
||||||
InetAddress m = InetAddress.getByName("239.255.255.250");
|
InetAddress m = InetAddress.getByName("239.255.255.250");
|
||||||
final int port = 1900;
|
final int port = 1900;
|
||||||
|
|
||||||
|
@ -154,7 +153,7 @@ public class VenstarThermostatDiscoveryService extends AbstractDiscoveryService
|
||||||
socket.joinGroup(m);
|
socket.joinGroup(m);
|
||||||
|
|
||||||
logger.trace("Joined UPnP Multicast group on Interface: {}", ni.getName());
|
logger.trace("Joined UPnP Multicast group on Interface: {}", ni.getName());
|
||||||
byte[] requestMessage = COLOR_TOUCH_DISCOVERY_MESSAGE.getBytes("UTF-8");
|
byte[] requestMessage = COLOR_TOUCH_DISCOVERY_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||||
DatagramPacket datagramPacket = new DatagramPacket(requestMessage, requestMessage.length, m, port);
|
DatagramPacket datagramPacket = new DatagramPacket(requestMessage, requestMessage.length, m, port);
|
||||||
socket.send(datagramPacket);
|
socket.send(datagramPacket);
|
||||||
return socket;
|
return socket;
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.zoneminder.internal.handler;
|
package org.openhab.binding.zoneminder.internal.handler;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
@ -61,14 +60,8 @@ public class ZmAuth {
|
||||||
logger.debug("ZmAuth: Authorization is enabled");
|
logger.debug("ZmAuth: Authorization is enabled");
|
||||||
usingAuthorization = true;
|
usingAuthorization = true;
|
||||||
isAuthorized = false;
|
isAuthorized = false;
|
||||||
String encodedUser = null;
|
String encodedUser = URLEncoder.encode(user, StandardCharsets.UTF_8);
|
||||||
String encodedPass = null;
|
String encodedPass = URLEncoder.encode(pass, StandardCharsets.UTF_8);
|
||||||
try {
|
|
||||||
encodedUser = URLEncoder.encode(user, StandardCharsets.UTF_8.name());
|
|
||||||
encodedPass = URLEncoder.encode(pass, StandardCharsets.UTF_8.name());
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
logger.warn("ZmAuth: Unable to encode user name and password");
|
|
||||||
}
|
|
||||||
authContent = encodedUser == null ? ""
|
authContent = encodedUser == null ? ""
|
||||||
: String.format("user=%s&pass=%s&stateful=1", encodedUser, encodedPass);
|
: String.format("user=%s&pass=%s&stateful=1", encodedUser, encodedPass);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.io.imperihome.internal.handler;
|
package org.openhab.io.imperihome.internal.handler;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -30,8 +30,6 @@ import org.slf4j.LoggerFactory;
|
||||||
*/
|
*/
|
||||||
public class DeviceActionHandler {
|
public class DeviceActionHandler {
|
||||||
|
|
||||||
private static final String CHARSET = "UTF-8";
|
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(DeviceActionHandler.class);
|
private final Logger logger = LoggerFactory.getLogger(DeviceActionHandler.class);
|
||||||
|
|
||||||
private final DeviceRegistry deviceRegistry;
|
private final DeviceRegistry deviceRegistry;
|
||||||
|
@ -42,17 +40,13 @@ public class DeviceActionHandler {
|
||||||
|
|
||||||
public void handle(HttpServletRequest req, Matcher urlMatcher) {
|
public void handle(HttpServletRequest req, Matcher urlMatcher) {
|
||||||
String deviceId, action, value;
|
String deviceId, action, value;
|
||||||
try {
|
deviceId = URLDecoder.decode(urlMatcher.group(1), StandardCharsets.UTF_8);
|
||||||
deviceId = URLDecoder.decode(urlMatcher.group(1), CHARSET);
|
action = URLDecoder.decode(urlMatcher.group(2), StandardCharsets.UTF_8);
|
||||||
action = URLDecoder.decode(urlMatcher.group(2), CHARSET);
|
|
||||||
|
|
||||||
if (urlMatcher.group(3) == null) {
|
if (urlMatcher.group(3) == null) {
|
||||||
value = null;
|
value = null;
|
||||||
} else {
|
} else {
|
||||||
value = URLDecoder.decode(urlMatcher.group(3), CHARSET);
|
value = URLDecoder.decode(urlMatcher.group(3), StandardCharsets.UTF_8);
|
||||||
}
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new RuntimeException("Could not decode request params", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("Action request for device {}: [{}] [{}]", deviceId, action, value);
|
logger.debug("Action request for device {}: [{}] [{}]", deviceId, action, value);
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.io.imperihome.internal.handler;
|
package org.openhab.io.imperihome.internal.handler;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
|
@ -45,8 +45,6 @@ import org.slf4j.LoggerFactory;
|
||||||
*/
|
*/
|
||||||
public class DeviceHistoryHandler {
|
public class DeviceHistoryHandler {
|
||||||
|
|
||||||
private static final String CHARSET = "UTF-8";
|
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(DeviceHistoryHandler.class);
|
private final Logger logger = LoggerFactory.getLogger(DeviceHistoryHandler.class);
|
||||||
|
|
||||||
private final DeviceRegistry deviceRegistry;
|
private final DeviceRegistry deviceRegistry;
|
||||||
|
@ -61,11 +59,11 @@ public class DeviceHistoryHandler {
|
||||||
String deviceId, field;
|
String deviceId, field;
|
||||||
long start, end;
|
long start, end;
|
||||||
try {
|
try {
|
||||||
deviceId = URLDecoder.decode(urlMatcher.group(1), CHARSET);
|
deviceId = URLDecoder.decode(urlMatcher.group(1), StandardCharsets.UTF_8);
|
||||||
field = URLDecoder.decode(urlMatcher.group(2), CHARSET);
|
field = URLDecoder.decode(urlMatcher.group(2), StandardCharsets.UTF_8);
|
||||||
start = Long.parseLong(urlMatcher.group(3));
|
start = Long.parseLong(urlMatcher.group(3));
|
||||||
end = Long.parseLong(urlMatcher.group(4));
|
end = Long.parseLong(urlMatcher.group(4));
|
||||||
} catch (UnsupportedEncodingException | NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new RuntimeException("Could not decode request params", e);
|
throw new RuntimeException("Could not decode request params", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ package org.openhab.io.neeo.internal;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
@ -158,16 +157,7 @@ public class NeeoUtil {
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
return URLDecoder.decode(s, StandardCharsets.UTF_8);
|
||||||
String result = null;
|
|
||||||
try {
|
|
||||||
result = URLDecoder.decode(s, StandardCharsets.UTF_8.name());
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
// This exception should never occur.
|
|
||||||
result = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,18 +170,8 @@ public class NeeoUtil {
|
||||||
*/
|
*/
|
||||||
public static String encodeURIComponent(String s) {
|
public static String encodeURIComponent(String s) {
|
||||||
requireNotEmpty(s, "s cannot be null or empty");
|
requireNotEmpty(s, "s cannot be null or empty");
|
||||||
String result = null;
|
return URLEncoder.encode(s, StandardCharsets.UTF_8).replaceAll("\\+", "%20").replaceAll("\\%21", "!")
|
||||||
|
.replaceAll("\\%27", "'").replaceAll("\\%28", "(").replaceAll("\\%29", ")").replaceAll("\\%7E", "~");
|
||||||
try {
|
|
||||||
result = URLEncoder.encode(s, "UTF-8").replaceAll("\\+", "%20").replaceAll("\\%21", "!")
|
|
||||||
.replaceAll("\\%27", "'").replaceAll("\\%28", "(").replaceAll("\\%29", ")")
|
|
||||||
.replaceAll("\\%7E", "~");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
// This exception should never occur.
|
|
||||||
result = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,9 +14,9 @@ package org.openhab.transform.javascript.internal;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -107,7 +107,7 @@ public class JavaScriptTransformationService implements TransformationService, C
|
||||||
filename = parts[0];
|
filename = parts[0];
|
||||||
try {
|
try {
|
||||||
vars = splitQuery(parts[1]);
|
vars = splitQuery(parts[1]);
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new TransformationException("Illegal filename syntax");
|
throw new TransformationException("Illegal filename syntax");
|
||||||
}
|
}
|
||||||
if (isReservedWordUsed(vars)) {
|
if (isReservedWordUsed(vars)) {
|
||||||
|
@ -142,16 +142,17 @@ public class JavaScriptTransformationService implements TransformationService, C
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> splitQuery(@Nullable String query) throws UnsupportedEncodingException {
|
private Map<String, String> splitQuery(@Nullable String query) throws IllegalArgumentException {
|
||||||
Map<String, String> result = new LinkedHashMap<>();
|
Map<String, String> result = new LinkedHashMap<>();
|
||||||
if (query != null) {
|
if (query != null) {
|
||||||
String[] pairs = query.split("&");
|
String[] pairs = query.split("&");
|
||||||
for (String pair : pairs) {
|
for (String pair : pairs) {
|
||||||
String[] keyval = pair.split("=");
|
String[] keyval = pair.split("=");
|
||||||
if (keyval.length != 2) {
|
if (keyval.length != 2) {
|
||||||
throw new UnsupportedEncodingException();
|
throw new IllegalArgumentException();
|
||||||
} else {
|
} else {
|
||||||
result.put(URLDecoder.decode(keyval[0], "UTF-8"), URLDecoder.decode(keyval[1], "UTF-8"));
|
result.put(URLDecoder.decode(keyval[0], StandardCharsets.UTF_8),
|
||||||
|
URLDecoder.decode(keyval[1], StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,11 @@ import static java.util.stream.Collectors.toSet;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -255,14 +255,7 @@ public class VoiceRSSCloudImpl implements VoiceRSSCloudAPI {
|
||||||
* It is in package scope to be accessed by tests.
|
* It is in package scope to be accessed by tests.
|
||||||
*/
|
*/
|
||||||
private String createURL(String apiKey, String text, String locale, String voice, String audioFormat) {
|
private String createURL(String apiKey, String text, String locale, String voice, String audioFormat) {
|
||||||
String encodedMsg;
|
String encodedMsg = URLEncoder.encode(text, StandardCharsets.UTF_8);
|
||||||
try {
|
|
||||||
encodedMsg = URLEncoder.encode(text, "UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException ex) {
|
|
||||||
logger.error("UnsupportedEncodingException for UTF-8 MUST NEVER HAPPEN! Check your JVM configuration!", ex);
|
|
||||||
// fall through and use msg un-encoded
|
|
||||||
encodedMsg = text;
|
|
||||||
}
|
|
||||||
String url = "http://api.voicerss.org/?key=" + apiKey + "&hl=" + locale + "&c=" + audioFormat;
|
String url = "http://api.voicerss.org/?key=" + apiKey + "&hl=" + locale + "&c=" + audioFormat;
|
||||||
if (!DEFAULT_VOICE.equals(voice)) {
|
if (!DEFAULT_VOICE.equals(voice)) {
|
||||||
url += "&v=" + voice;
|
url += "&v=" + voice;
|
||||||
|
|
|
@ -17,7 +17,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.measure.Unit;
|
import javax.measure.Unit;
|
||||||
|
@ -65,11 +65,11 @@ public final class WWNDataUtil {
|
||||||
// Hidden utility class constructor
|
// Hidden utility class constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Reader openDataReader(String fileName) throws UnsupportedEncodingException {
|
public static Reader openDataReader(String fileName) {
|
||||||
String packagePath = (WWNDataUtil.class.getPackage().getName()).replaceAll("\\.", "/");
|
String packagePath = (WWNDataUtil.class.getPackage().getName()).replaceAll("\\.", "/");
|
||||||
String filePath = "/" + packagePath + "/" + fileName;
|
String filePath = "/" + packagePath + "/" + fileName;
|
||||||
InputStream inputStream = WWNDataUtil.class.getClassLoader().getResourceAsStream(filePath);
|
InputStream inputStream = WWNDataUtil.class.getClassLoader().getResourceAsStream(filePath);
|
||||||
return new InputStreamReader(inputStream, "UTF-8");
|
return new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T fromJson(String fileName, Class<T> dataClass) throws IOException {
|
public static <T> T fromJson(String fileName, Class<T> dataClass) throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue