From 1dec0d0d5813df119bc8400d5862fc1f660044f1 Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 7 Sep 2020 12:20:04 +0200 Subject: [PATCH] [max] remove dependency on org.apache.commons.net.util (#8418) Replace org.apache.commons.net.util.Base64 with java.util.Base64 Signed-off-by: Marcel Verpaalen --- .../org/openhab/binding/max/internal/command/MCommand.java | 4 ++-- .../org/openhab/binding/max/internal/command/SCommand.java | 5 +++-- .../binding/max/internal/command/SConfigCommand.java | 5 +++-- .../org/openhab/binding/max/internal/command/TCommand.java | 4 ++-- .../org/openhab/binding/max/internal/message/CMessage.java | 5 ++--- .../org/openhab/binding/max/internal/message/LMessage.java | 6 +++--- .../org/openhab/binding/max/internal/message/MMessage.java | 4 ++-- .../org/openhab/binding/max/internal/message/NMessage.java | 6 +++--- 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/MCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/MCommand.java index 6e08679e47be1..18f9431fa65d0 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/MCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/MCommand.java @@ -16,12 +16,12 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Base64; import java.util.List; import java.util.Set; import java.util.TreeSet; import org.apache.commons.lang.StringUtils; -import org.apache.commons.net.util.Base64; import org.openhab.binding.max.internal.Utils; import org.openhab.binding.max.internal.device.Device; import org.openhab.binding.max.internal.device.RoomInformation; @@ -165,7 +165,7 @@ public String getCommandString() { } - final String encodedString = Base64.encodeBase64StringUnChunked(message.toByteArray()); + final String encodedString = Base64.getEncoder().encodeToString(message.toByteArray()); final StringBuilder commandStringBuilder = new StringBuilder(); int parts = (int) Math.round(encodedString.length() / MAX_MSG_LENGTH + 0.5); for (int i = 0; i < parts; i++) { diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SCommand.java index 9b15010f92704..04f5f508e8710 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SCommand.java @@ -12,7 +12,8 @@ */ package org.openhab.binding.max.internal.command; -import org.apache.commons.net.util.Base64; +import java.util.Base64; + import org.openhab.binding.max.internal.Utils; import org.openhab.binding.max.internal.device.ThermostatModeType; @@ -96,7 +97,7 @@ public String getCommandString() { final String commandString = baseString + rfAddress + Utils.toHex(roomId) + Utils.toHex(bits); - final String encodedString = Base64.encodeBase64String(Utils.hexStringToByteArray(commandString)); + final String encodedString = Base64.getEncoder().encodeToString(Utils.hexStringToByteArray(commandString)); return "s:" + encodedString; } diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SConfigCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SConfigCommand.java index 7e01862e059a5..611df2aafd176 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SConfigCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/SConfigCommand.java @@ -12,7 +12,8 @@ */ package org.openhab.binding.max.internal.command; -import org.apache.commons.net.util.Base64; +import java.util.Base64; + import org.openhab.binding.max.internal.Utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -151,7 +152,7 @@ public String getCommandString() { commandString = commandString + Utils.toHex(roomId) + commandConfigString; } - String encodedString = Base64.encodeBase64String(Utils.hexStringToByteArray(commandString)); + String encodedString = Base64.getEncoder().encodeToString(Utils.hexStringToByteArray(commandString)); return "s:" + encodedString; } diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/TCommand.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/TCommand.java index 486f8a88fbda0..7f258723e233d 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/TCommand.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/command/TCommand.java @@ -13,10 +13,10 @@ package org.openhab.binding.max.internal.command; import java.util.ArrayList; +import java.util.Base64; import java.util.List; import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.net.util.Base64; import org.openhab.binding.max.internal.Utils; /** @@ -51,7 +51,7 @@ public String getCommandString() { for (String rfAddress : rfAddresses) { commandArray = ArrayUtils.addAll(Utils.hexStringToByteArray(rfAddress), commandArray); } - String encodedString = Base64.encodeBase64StringUnChunked(commandArray); + String encodedString = Base64.getEncoder().encodeToString(commandArray); return "t:" + String.format("%02d", rfAddresses.size()) + "," + updateForced + "," + encodedString + '\r' + '\n'; diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/CMessage.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/CMessage.java index 2ca823e2616ca..213dcaa92d46a 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/CMessage.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/CMessage.java @@ -19,13 +19,13 @@ import java.math.RoundingMode; import java.nio.charset.StandardCharsets; import java.util.Arrays; +import java.util.Base64; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Map; import org.apache.commons.lang.StringUtils; -import org.apache.commons.net.util.Base64; import org.openhab.binding.max.internal.Utils; import org.openhab.binding.max.internal.device.DeviceType; import org.slf4j.Logger; @@ -67,8 +67,7 @@ public CMessage(String raw) { String[] tokens = this.getPayload().split(Message.DELIMETER); rfAddress = tokens[0]; - - byte[] bytes = Base64.decodeBase64(tokens[1].getBytes(StandardCharsets.UTF_8)); + byte[] bytes = Base64.getDecoder().decode((tokens[1].getBytes(StandardCharsets.UTF_8))); int[] data = new int[bytes.length]; diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/LMessage.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/LMessage.java index 24bf9348d1feb..b7152fbfbc77a 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/LMessage.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/LMessage.java @@ -14,10 +14,10 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Base64; import java.util.Collection; import java.util.List; -import org.apache.commons.net.util.Base64; import org.openhab.binding.max.internal.Utils; import org.openhab.binding.max.internal.device.Device; import org.openhab.binding.max.internal.device.DeviceConfiguration; @@ -39,7 +39,7 @@ public LMessage(String raw) { public Collection getDevices(List configurations) { final List devices = new ArrayList<>(); - final byte[] decodedRawMessage = Base64.decodeBase64(getPayload().getBytes(StandardCharsets.UTF_8)); + final byte[] decodedRawMessage = Base64.getDecoder().decode(getPayload().getBytes(StandardCharsets.UTF_8)); final MaxTokenizer tokenizer = new MaxTokenizer(decodedRawMessage); @@ -55,7 +55,7 @@ public Collection getDevices(List configu } public Collection updateDevices(List devices, List configurations) { - byte[] decodedRawMessage = Base64.decodeBase64(getPayload().getBytes(StandardCharsets.UTF_8)); + byte[] decodedRawMessage = Base64.getDecoder().decode(getPayload().getBytes(StandardCharsets.UTF_8)); MaxTokenizer tokenizer = new MaxTokenizer(decodedRawMessage); diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/MMessage.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/MMessage.java index f933fdf20a8d2..ada0d9e9a94a4 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/MMessage.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/MMessage.java @@ -14,9 +14,9 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Base64; import java.util.List; -import org.apache.commons.net.util.Base64; import org.openhab.binding.max.internal.Utils; import org.openhab.binding.max.internal.device.DeviceInformation; import org.openhab.binding.max.internal.device.DeviceType; @@ -49,7 +49,7 @@ public MMessage(String raw) { return; } try { - byte[] bytes = Base64.decodeBase64(tokens[2].getBytes(StandardCharsets.UTF_8)); + byte[] bytes = Base64.getDecoder().decode(tokens[2].getBytes(StandardCharsets.UTF_8)); hasConfiguration = true; logger.trace("*** M Message trace**** "); diff --git a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/NMessage.java b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/NMessage.java index 52ffbc4392fb0..385783a3506ce 100644 --- a/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/NMessage.java +++ b/bundles/org.openhab.binding.max/src/main/java/org/openhab/binding/max/internal/message/NMessage.java @@ -13,8 +13,8 @@ package org.openhab.binding.max.internal.message; import java.nio.charset.StandardCharsets; +import java.util.Base64; -import org.apache.commons.net.util.Base64; import org.openhab.binding.max.internal.Utils; import org.openhab.binding.max.internal.device.DeviceType; import org.slf4j.Logger; @@ -45,8 +45,8 @@ public NMessage(String raw) { if (msgPayload.length() > 0) { try { - decodedPayload = new String(Base64.decodeBase64(msgPayload), StandardCharsets.UTF_8); - byte[] bytes = Base64.decodeBase64(msgPayload); + decodedPayload = new String(Base64.getDecoder().decode(msgPayload), StandardCharsets.UTF_8); + byte[] bytes = Base64.getDecoder().decode(msgPayload); deviceType = DeviceType.create(bytes[0] & 0xFF); rfAddress = Utils.toHex(bytes[1] & 0xFF, bytes[2] & 0xFF, bytes[3] & 0xFF);