From dec3b44f3fa802ae627a822b65bb694060f2df80 Mon Sep 17 00:00:00 2001
From: lolodomo <lg.hc@free.fr>
Date: Mon, 25 May 2020 17:51:26 +0200
Subject: [PATCH] [oceanic] Removed dependency on
 'org.apache.commons.io.IOUtils' (#7732)

Relative to #7722

Let the socket closure close the in/out streams

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
---
 .../handler/NetworkOceanicThingHandler.java   |  5 ++--
 .../handler/SerialOceanicThingHandler.java    | 23 +++++++++++++++----
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/NetworkOceanicThingHandler.java b/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/NetworkOceanicThingHandler.java
index 2d1a3a3a15266..3ae12b956de41 100644
--- a/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/NetworkOceanicThingHandler.java
+++ b/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/NetworkOceanicThingHandler.java
@@ -21,7 +21,6 @@
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.eclipse.smarthome.core.thing.Thing;
 import org.eclipse.smarthome.core.thing.ThingStatus;
@@ -83,8 +82,6 @@ public void initialize() {
     public void dispose() {
         NetworkOceanicBindingConfiguration config = getConfigAs(NetworkOceanicBindingConfiguration.class);
 
-        IOUtils.closeQuietly(inputStream);
-        IOUtils.closeQuietly(outputStream);
         if (socket != null) {
             try {
                 socket.close();
@@ -93,6 +90,8 @@ public void dispose() {
                         config.portNumber, e.getMessage());
             } finally {
                 socket = null;
+                outputStream = null;
+                inputStream = null;
             }
         }
 
diff --git a/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/SerialOceanicThingHandler.java b/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/SerialOceanicThingHandler.java
index 550ffa6e4fa51..9945c8a05a612 100644
--- a/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/SerialOceanicThingHandler.java
+++ b/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/SerialOceanicThingHandler.java
@@ -19,7 +19,6 @@
 import java.util.Arrays;
 import java.util.Enumeration;
 
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.eclipse.smarthome.core.thing.Thing;
 import org.eclipse.smarthome.core.thing.ThingStatus;
@@ -149,12 +148,29 @@ public void dispose() {
             }
         }
 
-        IOUtils.closeQuietly(inputStream);
-        IOUtils.closeQuietly(outputStream);
+        if (inputStream != null) {
+            try {
+                inputStream.close();
+            } catch (IOException e) {
+                logger.debug("Error while closing the input stream: {}", e.getMessage());
+            }
+        }
+        if (outputStream != null) {
+            try {
+                outputStream.close();
+            } catch (IOException e) {
+                logger.debug("Error while closing the output stream: {}", e.getMessage());
+            }
+        }
         if (serialPort != null) {
             serialPort.close();
         }
 
+        readerThread = null;
+        inputStream = null;
+        outputStream = null;
+        serialPort = null;
+
         super.dispose();
     }
 
@@ -224,7 +240,6 @@ public void interrupt() {
             logger.trace("Interrupting the SerialPortReader");
             interrupted = true;
             super.interrupt();
-            IOUtils.closeQuietly(inputStream);
         }
 
         @Override