mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-30 17:12:01 +01:00
Refactor usages of deprecated methods (#18082)
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
3c90a0dcf9
commit
3827872c20
@ -12,7 +12,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.binding.lgwebos.internal;
|
package org.openhab.binding.lgwebos.internal;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@ -23,6 +25,7 @@ import java.util.Enumeration;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
@ -170,7 +173,16 @@ public class WakeOnLanUtility {
|
|||||||
|
|
||||||
private static boolean checkIfLinuxCommandExists(String cmd) {
|
private static boolean checkIfLinuxCommandExists(String cmd) {
|
||||||
try {
|
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) {
|
} catch (InterruptedException | IOException e) {
|
||||||
LOGGER.debug("Error trying to check if command {} exists: {}", cmd, e.getMessage());
|
LOGGER.debug("Error trying to check if command {} exists: {}", cmd, e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,8 @@ import java.awt.image.BufferedImage;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -100,11 +101,11 @@ public class LGWebOSActions implements ThingActions {
|
|||||||
public void showToast(
|
public void showToast(
|
||||||
@ActionInput(name = "icon", label = "@text/actionShowToastInputIconLabel", description = "@text/actionShowToastInputIconDesc") String icon,
|
@ActionInput(name = "icon", label = "@text/actionShowToastInputIconLabel", description = "@text/actionShowToastInputIconDesc") String icon,
|
||||||
@ActionInput(name = "text", label = "@text/actionShowToastInputTextLabel", description = "@text/actionShowToastInputTextDesc") String text)
|
@ActionInput(name = "text", label = "@text/actionShowToastInputTextLabel", description = "@text/actionShowToastInputTextDesc") String text)
|
||||||
throws IOException {
|
throws IOException, URISyntaxException {
|
||||||
BufferedImage bi = ImageIO.read(new URL(icon));
|
BufferedImage bi = ImageIO.read(new URI(icon).toURL());
|
||||||
try (ByteArrayOutputStream os = new ByteArrayOutputStream(); OutputStream b64 = Base64.getEncoder().wrap(os)) {
|
try (ByteArrayOutputStream os = new ByteArrayOutputStream(); OutputStream b64 = Base64.getEncoder().wrap(os)) {
|
||||||
ImageIO.write(bi, "png", b64);
|
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()));
|
getConnectedSocket().ifPresent(control -> control.showToast(text, string, "png", createResponseListener()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,7 +262,8 @@ public class LGWebOSActions implements ThingActions {
|
|||||||
((LGWebOSActions) actions).showToast(text);
|
((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);
|
((LGWebOSActions) actions).showToast(icon, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user