Skip to content

Commit 3827872

Browse files
authored
Refactor usages of deprecated methods (openhab#18082)
Signed-off-by: Jacob Laursen <[email protected]>
1 parent 3c90a0d commit 3827872

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/WakeOnLanUtility.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
*/
1313
package org.openhab.binding.lgwebos.internal;
1414

15+
import java.io.BufferedReader;
1516
import java.io.IOException;
17+
import java.io.InputStreamReader;
1618
import java.net.DatagramPacket;
1719
import java.net.DatagramSocket;
1820
import java.net.InetAddress;
@@ -23,6 +25,7 @@
2325
import java.util.Objects;
2426
import java.util.regex.Matcher;
2527
import java.util.regex.Pattern;
28+
import java.util.stream.Collectors;
2629
import java.util.stream.Stream;
2730

2831
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -170,7 +173,16 @@ private static byte[] getWOLPackage(String macStr) throws IllegalArgumentExcepti
170173

171174
private static boolean checkIfLinuxCommandExists(String cmd) {
172175
try {
173-
return 0 == Runtime.getRuntime().exec(String.format("which %s", cmd)).waitFor();
176+
Process process = new ProcessBuilder("which", cmd).redirectErrorStream(true).start();
177+
178+
if (LOGGER.isDebugEnabled()) {
179+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
180+
String output = reader.lines().collect(Collectors.joining("\n"));
181+
LOGGER.debug("Command 'which {}' returned {}", cmd, output);
182+
}
183+
}
184+
185+
return process.waitFor() == 0;
174186
} catch (InterruptedException | IOException e) {
175187
LOGGER.debug("Error trying to check if command {} exists: {}", cmd, e.getMessage());
176188
}

bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/action/LGWebOSActions.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
import java.io.ByteArrayOutputStream;
1717
import java.io.IOException;
1818
import java.io.OutputStream;
19-
import java.net.URL;
19+
import java.net.URI;
20+
import java.net.URISyntaxException;
2021
import java.nio.charset.StandardCharsets;
2122
import java.util.Base64;
2223
import java.util.Collections;
@@ -100,11 +101,11 @@ public void showToast(
100101
public void showToast(
101102
@ActionInput(name = "icon", label = "@text/actionShowToastInputIconLabel", description = "@text/actionShowToastInputIconDesc") String icon,
102103
@ActionInput(name = "text", label = "@text/actionShowToastInputTextLabel", description = "@text/actionShowToastInputTextDesc") String text)
103-
throws IOException {
104-
BufferedImage bi = ImageIO.read(new URL(icon));
104+
throws IOException, URISyntaxException {
105+
BufferedImage bi = ImageIO.read(new URI(icon).toURL());
105106
try (ByteArrayOutputStream os = new ByteArrayOutputStream(); OutputStream b64 = Base64.getEncoder().wrap(os)) {
106107
ImageIO.write(bi, "png", b64);
107-
String string = os.toString(StandardCharsets.UTF_8.name());
108+
String string = os.toString(StandardCharsets.UTF_8);
108109
getConnectedSocket().ifPresent(control -> control.showToast(text, string, "png", createResponseListener()));
109110
}
110111
}
@@ -261,7 +262,8 @@ public static void showToast(ThingActions actions, String text) throws IOExcepti
261262
((LGWebOSActions) actions).showToast(text);
262263
}
263264

264-
public static void showToast(ThingActions actions, String icon, String text) throws IOException {
265+
public static void showToast(ThingActions actions, String icon, String text)
266+
throws IOException, URISyntaxException {
265267
((LGWebOSActions) actions).showToast(icon, text);
266268
}
267269

0 commit comments

Comments
 (0)