import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Arrays;
+import java.util.Objects;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
-import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.oceanic.internal.NetworkOceanicBindingConfiguration;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
+import org.openhab.core.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
NetworkOceanicBindingConfiguration config = getConfigAs(NetworkOceanicBindingConfiguration.class);
try {
- socket = new Socket(config.ipAddress, config.portNumber);
- if (socket != null) {
- socket.setSoTimeout(REQUEST_TIMEOUT);
- outputStream = socket.getOutputStream();
- inputStream = socket.getInputStream();
- updateStatus(ThingStatus.ONLINE);
- }
+ Socket socket = new Socket(config.ipAddress, config.portNumber);
+ this.socket = socket;
+ socket.setSoTimeout(REQUEST_TIMEOUT);
+ outputStream = socket.getOutputStream();
+ inputStream = socket.getInputStream();
+ updateStatus(ThingStatus.ONLINE);
} catch (UnknownHostException e) {
logger.error("An exception occurred while resolving host {}:{} : '{}'", config.ipAddress, config.portNumber,
e.getMessage());
@Override
public void dispose() {
NetworkOceanicBindingConfiguration config = getConfigAs(NetworkOceanicBindingConfiguration.class);
-
+ Socket socket = this.socket;
if (socket != null) {
try {
socket.close();
logger.error("An exception occurred while disconnecting to host {}:{} : '{}'", config.ipAddress,
config.portNumber, e.getMessage());
} finally {
- socket = null;
+ this.socket = null;
outputStream = null;
inputStream = null;
}
if (index > 0) {
line = new String(Arrays.copyOf(dataBuffer, index));
logger.debug("Received response '{}'", line);
- line = StringUtils.chomp(line);
+ line = Objects.requireNonNull(StringUtils.chomp(line));
line = line.replace(",", ".");
line = line.trim();
index = 0;
} else {
bufferSize = ((BigDecimal) getConfig().get(BUFFER_SIZE)).intValue();
}
-
+ ScheduledFuture<?> pollingJob = this.pollingJob;
if (pollingJob == null || pollingJob.isCancelled()) {
- pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 1,
+ this.pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 1,
((BigDecimal) getConfig().get(INTERVAL)).intValue(), TimeUnit.SECONDS);
}
}
@Override
public void dispose() {
- if (pollingJob != null && !pollingJob.isCancelled()) {
+ ScheduledFuture<?> pollingJob = this.pollingJob;
+ if (pollingJob != null) {
pollingJob.cancel(true);
- pollingJob = null;
+ this.pollingJob = null;
}
}
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Arrays;
+import java.util.Objects;
import java.util.TooManyListenersException;
import java.util.stream.Collectors;
-import org.apache.commons.lang3.StringUtils;
import org.openhab.binding.oceanic.internal.SerialOceanicBindingConfiguration;
import org.openhab.binding.oceanic.internal.Throttler;
import org.openhab.core.io.transport.serial.PortInUseException;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
+import org.openhab.core.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
logger.trace("The resulting line is '{}'",
new String(Arrays.copyOf(dataBuffer, index)));
}
- line = StringUtils.chomp(new String(Arrays.copyOf(dataBuffer, index)));
+ line = Objects.requireNonNull(
+ StringUtils.chomp(new String(Arrays.copyOf(dataBuffer, index))));
line = line.replace(",", ".");
line = line.trim();
index = 0;