From f9b8b738fd5a1d329581756610c8fb825f9829d0 Mon Sep 17 00:00:00 2001 From: lolodomo Date: Mon, 25 May 2020 17:49:22 +0200 Subject: [PATCH] [powermax] Removed dependency on 'org.apache.commons.io.IOUtils' (#7728) * [powermax] Removed dependency on 'org.apache.commons.io.IOUtils' Relative to #7722 Signed-off-by: Laurent Garnier --- .../internal/connector/PowermaxConnector.java | 23 +++++++++++++------ .../connector/PowermaxSerialConnector.java | 2 +- .../connector/PowermaxTcpConnector.java | 9 +++++--- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/connector/PowermaxConnector.java b/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/connector/PowermaxConnector.java index 65c8a566a3d87..0da7f1dbf082d 100644 --- a/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/connector/PowermaxConnector.java +++ b/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/connector/PowermaxConnector.java @@ -18,7 +18,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.commons.io.IOUtils; import org.openhab.binding.powermax.internal.message.PowermaxBaseMessage; import org.openhab.binding.powermax.internal.message.PowermaxMessageEvent; import org.openhab.binding.powermax.internal.message.PowermaxMessageEventListener; @@ -51,7 +50,7 @@ public abstract class PowermaxConnector implements PowermaxConnectorInterface { /** * Cleanup everything; to be called when closing the communication */ - protected void cleanup() { + protected void cleanup(boolean closeStreams) { logger.debug("cleanup(): cleaning up Connection"); if (readerThread != null) { @@ -62,12 +61,22 @@ protected void cleanup() { } } - if (output != null) { - IOUtils.closeQuietly(output); - } + if (closeStreams) { + if (output != null) { + try { + output.close(); + } catch (IOException e) { + logger.debug("Error while closing the output stream: {}", e.getMessage()); + } + } - if (input != null) { - IOUtils.closeQuietly(input); + if (input != null) { + try { + input.close(); + } catch (IOException e) { + logger.debug("Error while closing the input stream: {}", e.getMessage()); + } + } } readerThread = null; diff --git a/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/connector/PowermaxSerialConnector.java b/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/connector/PowermaxSerialConnector.java index 9a87b04e534ba..af98248516fc9 100644 --- a/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/connector/PowermaxSerialConnector.java +++ b/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/connector/PowermaxSerialConnector.java @@ -118,7 +118,7 @@ public void close() { serialPort.removeEventListener(); } - super.cleanup(); + super.cleanup(true); if (serialPort != null) { serialPort.close(); diff --git a/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/connector/PowermaxTcpConnector.java b/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/connector/PowermaxTcpConnector.java index 3c4a558f1eb39..f5bb3fa0d7c4b 100644 --- a/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/connector/PowermaxTcpConnector.java +++ b/bundles/org.openhab.binding.powermax/src/main/java/org/openhab/binding/powermax/internal/connector/PowermaxTcpConnector.java @@ -20,7 +20,6 @@ import java.net.SocketTimeoutException; import java.net.UnknownHostException; -import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -87,10 +86,14 @@ public void open() { public void close() { logger.debug("close(): Closing TCP Connection"); - super.cleanup(); + super.cleanup(false); if (tcpSocket != null) { - IOUtils.closeQuietly(tcpSocket); + try { + tcpSocket.close(); + } catch (IOException e) { + logger.debug("Error while closing the socket: {}", e.getMessage()); + } } tcpSocket = null;