Skip to content

Commit

Permalink
Refactor usages of deprecated methods (openhab#18082)
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur authored Jan 11, 2025
1 parent 3c90a0d commit 3827872
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
*/
package org.openhab.binding.lgwebos.internal;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
Expand All @@ -23,6 +25,7 @@
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

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

private static boolean checkIfLinuxCommandExists(String cmd) {
try {
return 0 == Runtime.getRuntime().exec(String.format("which %s", cmd)).waitFor();
Process process = new ProcessBuilder("which", cmd).redirectErrorStream(true).start();

if (LOGGER.isDebugEnabled()) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String output = reader.lines().collect(Collectors.joining("\n"));
LOGGER.debug("Command 'which {}' returned {}", cmd, output);
}
}

return process.waitFor() == 0;
} catch (InterruptedException | IOException e) {
LOGGER.debug("Error trying to check if command {} exists: {}", cmd, e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Collections;
Expand Down Expand Up @@ -100,11 +101,11 @@ public void showToast(
public void showToast(
@ActionInput(name = "icon", label = "@text/actionShowToastInputIconLabel", description = "@text/actionShowToastInputIconDesc") String icon,
@ActionInput(name = "text", label = "@text/actionShowToastInputTextLabel", description = "@text/actionShowToastInputTextDesc") String text)
throws IOException {
BufferedImage bi = ImageIO.read(new URL(icon));
throws IOException, URISyntaxException {
BufferedImage bi = ImageIO.read(new URI(icon).toURL());
try (ByteArrayOutputStream os = new ByteArrayOutputStream(); OutputStream b64 = Base64.getEncoder().wrap(os)) {
ImageIO.write(bi, "png", b64);
String string = os.toString(StandardCharsets.UTF_8.name());
String string = os.toString(StandardCharsets.UTF_8);
getConnectedSocket().ifPresent(control -> control.showToast(text, string, "png", createResponseListener()));
}
}
Expand Down Expand Up @@ -261,7 +262,8 @@ public static void showToast(ThingActions actions, String text) throws IOExcepti
((LGWebOSActions) actions).showToast(text);
}

public static void showToast(ThingActions actions, String icon, String text) throws IOException {
public static void showToast(ThingActions actions, String icon, String text)
throws IOException, URISyntaxException {
((LGWebOSActions) actions).showToast(icon, text);
}

Expand Down

0 comments on commit 3827872

Please sign in to comment.