From 6957f7ac56b32462861cc9684a1567eb7c88ddfd Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Fri, 22 May 2020 10:12:26 +0200 Subject: [PATCH 1/3] [powermax] Removed dependency on 'org.apache.commons.io.IOUtils' Relative to #7722 Signed-off-by: Laurent Garnier --- .../internal/connector/PowermaxConnector.java | 11 ++++++++--- .../internal/connector/PowermaxTcpConnector.java | 6 ++++-- 2 files changed, 12 insertions(+), 5 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..265663f3489b7 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; @@ -63,11 +62,17 @@ protected void cleanup() { } if (output != null) { - IOUtils.closeQuietly(output); + try { + output.close(); + } catch (IOException e) { + } } if (input != null) { - IOUtils.closeQuietly(input); + try { + input.close(); + } catch (IOException e) { + } } readerThread = null; 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..1fc9c969ab05b 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; @@ -90,7 +89,10 @@ public void close() { super.cleanup(); if (tcpSocket != null) { - IOUtils.closeQuietly(tcpSocket); + try { + tcpSocket.close(); + } catch (IOException e) { + } } tcpSocket = null; From a374d10bf720589cb347077bcf6f7e1a6b6ba573 Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Fri, 22 May 2020 16:08:21 +0200 Subject: [PATCH 2/3] Log added in case of error while closing input/output stream Singed-off-by: Laurent Garnier --- .../binding/powermax/internal/connector/PowermaxConnector.java | 2 ++ .../powermax/internal/connector/PowermaxTcpConnector.java | 1 + 2 files changed, 3 insertions(+) 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 265663f3489b7..07d39c7b34e35 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 @@ -65,6 +65,7 @@ protected void cleanup() { try { output.close(); } catch (IOException e) { + logger.debug("Error while closing the output stream: {}", e.getMessage()); } } @@ -72,6 +73,7 @@ protected void cleanup() { try { input.close(); } catch (IOException e) { + logger.debug("Error while closing the input stream: {}", e.getMessage()); } } 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 1fc9c969ab05b..14acff25270d1 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 @@ -92,6 +92,7 @@ public void close() { try { tcpSocket.close(); } catch (IOException e) { + logger.debug("Error while closing the socket: {}", e.getMessage()); } } From 5e321536215c993ba1a34938a22ddb24e87e4035 Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Sat, 23 May 2020 14:23:55 +0200 Subject: [PATCH 3/3] In/out streams closed when the socket is closed Signed-off-by: Laurent Garnier --- .../internal/connector/PowermaxConnector.java | 26 ++++++++++--------- .../connector/PowermaxSerialConnector.java | 2 +- .../connector/PowermaxTcpConnector.java | 2 +- 3 files changed, 16 insertions(+), 14 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 07d39c7b34e35..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 @@ -50,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) { @@ -61,19 +61,21 @@ protected void cleanup() { } } - if (output != null) { - try { - output.close(); - } catch (IOException e) { - logger.debug("Error while closing the output stream: {}", e.getMessage()); + if (closeStreams) { + if (output != null) { + try { + output.close(); + } catch (IOException e) { + logger.debug("Error while closing the output stream: {}", e.getMessage()); + } } - } - if (input != null) { - try { - input.close(); - } catch (IOException e) { - logger.debug("Error while closing the input stream: {}", e.getMessage()); + if (input != null) { + try { + input.close(); + } catch (IOException e) { + logger.debug("Error while closing the input stream: {}", e.getMessage()); + } } } 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 14acff25270d1..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 @@ -86,7 +86,7 @@ public void open() { public void close() { logger.debug("close(): Closing TCP Connection"); - super.cleanup(); + super.cleanup(false); if (tcpSocket != null) { try {