]> git.basschouten.com Git - openhab-addons.git/commitdiff
Correct error for long thing names (#12708)
authorMark Herwege <mherwege@users.noreply.github.com>
Mon, 9 May 2022 21:05:30 +0000 (23:05 +0200)
committerGitHub <noreply@github.com>
Mon, 9 May 2022 21:05:30 +0000 (23:05 +0200)
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/util/ElroConnectsUtil.java

index 7fe252eef210813bacfa564ddc85e9b3a3293657..8c6207a7f8b8e41d457a9af4c73744f9bf19da9b 100644 (file)
@@ -46,8 +46,10 @@ public final class ElroConnectsUtil {
      */
     public static String encode(String input, int length) {
         byte[] bytes = input.getBytes(StandardCharsets.UTF_8);
-        String content = "@".repeat(length - bytes.length) + new String(bytes, StandardCharsets.UTF_8) + "$";
-        bytes = content.getBytes(StandardCharsets.UTF_8);
+        String content = "@".repeat((length > bytes.length) ? (length - bytes.length) : 0)
+                + new String(bytes, StandardCharsets.UTF_8);
+        bytes = Arrays.copyOf(content.getBytes(StandardCharsets.UTF_8), length);
+        bytes[length] = (byte) "$".charAt(0);
         return HexUtils.bytesToHex(bytes);
     }