From cb426a07e7c84ed8b38a5fded3762eae96bd822b Mon Sep 17 00:00:00 2001 From: lolodomo Date: Mon, 25 May 2020 17:52:35 +0200 Subject: [PATCH] [lirc] Removed dependency on 'org.apache.commons.io.IOUtils' (#7733) Relative to #7722 Let the socket closure close the in/out streams Signed-off-by: Laurent Garnier Signed-off-by: CSchlipp --- .../internal/connector/LIRCConnector.java | 21 +++++++------------ .../internal/connector/LIRCStreamReader.java | 7 +++++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/bundles/org.openhab.binding.lirc/src/main/java/org/openhab/binding/lirc/internal/connector/LIRCConnector.java b/bundles/org.openhab.binding.lirc/src/main/java/org/openhab/binding/lirc/internal/connector/LIRCConnector.java index 208f6ffdb4339..53b17cc0fb0ed 100644 --- a/bundles/org.openhab.binding.lirc/src/main/java/org/openhab/binding/lirc/internal/connector/LIRCConnector.java +++ b/bundles/org.openhab.binding.lirc/src/main/java/org/openhab/binding/lirc/internal/connector/LIRCConnector.java @@ -21,7 +21,6 @@ import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; -import org.apache.commons.io.IOUtils; import org.openhab.binding.lirc.internal.config.LIRCBridgeConfiguration; import org.openhab.binding.lirc.internal.messages.LIRCButtonEvent; import org.openhab.binding.lirc.internal.messages.LIRCResponse; @@ -75,23 +74,19 @@ public void disconnect() { } if (outWriter != null) { logger.debug("Close print writer stream"); - IOUtils.closeQuietly(outWriter); + outWriter.close(); outWriter = null; } - if (out != null) { - logger.debug("Close tcp out stream"); - IOUtils.closeQuietly(out); - out = null; - } - if (in != null) { - logger.debug("Close tcp in stream"); - IOUtils.closeQuietly(in); - in = null; - } if (socket != null) { logger.debug("Close socket"); - IOUtils.closeQuietly(socket); + try { + socket.close(); + } catch (IOException e) { + logger.debug("Error while closing the socket: {}", e.getMessage()); + } socket = null; + out = null; + in = null; } logger.debug("Disconnected"); } diff --git a/bundles/org.openhab.binding.lirc/src/main/java/org/openhab/binding/lirc/internal/connector/LIRCStreamReader.java b/bundles/org.openhab.binding.lirc/src/main/java/org/openhab/binding/lirc/internal/connector/LIRCStreamReader.java index aad07357ddaa4..71d18f67ed446 100644 --- a/bundles/org.openhab.binding.lirc/src/main/java/org/openhab/binding/lirc/internal/connector/LIRCStreamReader.java +++ b/bundles/org.openhab.binding.lirc/src/main/java/org/openhab/binding/lirc/internal/connector/LIRCStreamReader.java @@ -22,7 +22,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.io.IOUtils; import org.openhab.binding.lirc.internal.LIRCResponseException; import org.openhab.binding.lirc.internal.messages.LIRCButtonEvent; import org.openhab.binding.lirc.internal.messages.LIRCResponse; @@ -104,7 +103,11 @@ public void run() { logger.error("Invalid message received", e); } } - IOUtils.closeQuietly(reader); + try { + reader.close(); + } catch (IOException e) { + logger.debug("Error while closing the input stream: {}", e.getMessage()); + } } private void processResponse(String responseText) throws LIRCResponseException {