Skip to content

Commit

Permalink
[powermax] Removed dependency on 'org.apache.commons.io.IOUtils' (ope…
Browse files Browse the repository at this point in the history
…nhab#7728)

* [powermax] Removed dependency on 'org.apache.commons.io.IOUtils'

Relative to openhab#7722

Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo authored and bodiroga committed May 26, 2020
1 parent 18effea commit f9b8b73
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.openhab.binding.powermax.internal.message.PowermaxBaseMessage;
import org.openhab.binding.powermax.internal.message.PowermaxMessageEvent;
import org.openhab.binding.powermax.internal.message.PowermaxMessageEventListener;
Expand Down Expand Up @@ -51,7 +50,7 @@ public abstract class PowermaxConnector implements PowermaxConnectorInterface {
/**
* Cleanup everything; to be called when closing the communication
*/
protected void cleanup() {
protected void cleanup(boolean closeStreams) {
logger.debug("cleanup(): cleaning up Connection");

if (readerThread != null) {
Expand All @@ -62,12 +61,22 @@ protected void cleanup() {
}
}

if (output != null) {
IOUtils.closeQuietly(output);
}
if (closeStreams) {
if (output != null) {
try {
output.close();
} catch (IOException e) {
logger.debug("Error while closing the output stream: {}", e.getMessage());
}
}

if (input != null) {
IOUtils.closeQuietly(input);
if (input != null) {
try {
input.close();
} catch (IOException e) {
logger.debug("Error while closing the input stream: {}", e.getMessage());
}
}
}

readerThread = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void close() {
serialPort.removeEventListener();
}

super.cleanup();
super.cleanup(true);

if (serialPort != null) {
serialPort.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -87,10 +86,14 @@ public void open() {
public void close() {
logger.debug("close(): Closing TCP Connection");

super.cleanup();
super.cleanup(false);

if (tcpSocket != null) {
IOUtils.closeQuietly(tcpSocket);
try {
tcpSocket.close();
} catch (IOException e) {
logger.debug("Error while closing the socket: {}", e.getMessage());
}
}

tcpSocket = null;
Expand Down

0 comments on commit f9b8b73

Please sign in to comment.