Skip to content

Commit

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

Interrupt the reader thread first in dispose()

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo authored May 25, 2020
1 parent 8900180 commit 5969085
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 5969085

Please sign in to comment.