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: CSchlipp <christian@schlipp.de>
  • Loading branch information
lolodomo authored and CSchlipp committed Jul 26, 2020
1 parent 387e89f commit 35ee9c9
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 35ee9c9

Please sign in to comment.