Skip to content

Commit

Permalink
[rme] Removed dependency on 'org.apache.commons.io.IOUtils' (openhab#…
Browse files Browse the repository at this point in the history
…7735)

Relative to openhab#7722

Interrupt the reader thread first in dispose()

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Signed-off-by: Daan Meijer <daan@studioseptember.nl>
  • Loading branch information
lolodomo authored and DaanMeijer committed Sep 1, 2020
1 parent 954a811 commit 81ec6c0
Showing 1 changed file with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -123,20 +122,34 @@ 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();
readerThread.join();
} 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
Expand Down Expand Up @@ -240,10 +253,6 @@ public SerialPortReader(InputStream in) {
public void interrupt() {
interrupted = true;
super.interrupt();
try {
inputStream.close();
} catch (IOException e) {
} // quietly close
}

@Override
Expand Down

0 comments on commit 81ec6c0

Please sign in to comment.