Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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