From 81ec6c06b85ab2f3ecca69fb187669a433efc82c Mon Sep 17 00:00:00 2001 From: lolodomo Date: Mon, 25 May 2020 20:00:46 +0200 Subject: [PATCH] [rme] Removed dependency on 'org.apache.commons.io.IOUtils' (#7735) Relative to #7722 Interrupt the reader thread first in dispose() Signed-off-by: Laurent Garnier Signed-off-by: Daan Meijer --- .../internal/handler/SerialThingHandler.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/bundles/org.openhab.binding.rme/src/main/java/org/openhab/binding/rme/internal/handler/SerialThingHandler.java b/bundles/org.openhab.binding.rme/src/main/java/org/openhab/binding/rme/internal/handler/SerialThingHandler.java index 5f8456df356b4..9b8b89233b692 100644 --- a/bundles/org.openhab.binding.rme/src/main/java/org/openhab/binding/rme/internal/handler/SerialThingHandler.java +++ b/bundles/org.openhab.binding.rme/src/main/java/org/openhab/binding/rme/internal/handler/SerialThingHandler.java @@ -21,7 +21,6 @@ import java.util.TooManyListenersException; import java.util.stream.Collectors; -import org.apache.commons.io.IOUtils; import org.eclipse.smarthome.core.thing.ChannelUID; import org.eclipse.smarthome.core.thing.Thing; import org.eclipse.smarthome.core.thing.ThingStatus; @@ -123,13 +122,6 @@ public void dispose() { if (serialPort != null) { serialPort.removeEventListener(); } - IOUtils.closeQuietly(inputStream); - IOUtils.closeQuietly(outputStream); - if (serialPort != null) { - serialPort.close(); - serialPort = null; - } - if (readerThread != null) { try { readerThread.interrupt(); @@ -137,6 +129,27 @@ public void dispose() { } catch (InterruptedException e) { } } + 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; } @Override @@ -240,10 +253,6 @@ public SerialPortReader(InputStream in) { public void interrupt() { interrupted = true; super.interrupt(); - try { - inputStream.close(); - } catch (IOException e) { - } // quietly close } @Override