You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2018/03/05 20:45:54 UTC

[incubator-plc4x] branch master updated (e07180c -> a486574)

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git.


    from e07180c  increase performance by eliminating loops for building.
     new 788eeea  Prevented errors when providing no parameters via URL
     new a486574  Refactored LittleEndianEncoder to avoid that one D-Level SonarQube warning.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/ads/netty/util/LittleEndianEncoder.java   | 31 +++++++++++++---------
 .../java/org/apache/plc4x/java/s7/S7PlcDriver.java |  2 +-
 2 files changed, 19 insertions(+), 14 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
cdutz@apache.org.

[incubator-plc4x] 01/02: Prevented errors when providing no parameters via URL

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 788eeea8d210707b4c990b2e0098f25d434e4d2c
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Mar 5 14:49:34 2018 +0100

    Prevented errors when providing no parameters via URL
---
 .../s7/src/main/java/org/apache/plc4x/java/s7/S7PlcDriver.java          | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/S7PlcDriver.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/S7PlcDriver.java
index 3da29f7..1d6b576 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/S7PlcDriver.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/S7PlcDriver.java
@@ -61,7 +61,7 @@ public class S7PlcDriver implements PlcDriver {
 
         int rack = Integer.parseInt(matcher.group("rack"));
         int slot = Integer.parseInt(matcher.group("slot"));
-        String params = matcher.group("params").substring(1);
+        String params = matcher.group("params") != null ? matcher.group("params").substring(1) : null;
 
         try {
             InetAddress serverInetAddress = InetAddress.getByName(host);

-- 
To stop receiving notification emails like this one, please contact
cdutz@apache.org.

[incubator-plc4x] 02/02: Refactored LittleEndianEncoder to avoid that one D-Level SonarQube warning.

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit a486574f3ea1b1a0de5d803631fe887d5b63f058
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Mar 5 21:45:39 2018 +0100

    Refactored LittleEndianEncoder to avoid that one D-Level SonarQube warning.
---
 .../java/ads/netty/util/LittleEndianEncoder.java   | 31 +++++++++++++---------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/netty/util/LittleEndianEncoder.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/netty/util/LittleEndianEncoder.java
index 20c84af..329d60b 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/netty/util/LittleEndianEncoder.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/netty/util/LittleEndianEncoder.java
@@ -20,6 +20,7 @@ package org.apache.plc4x.java.ads.netty.util;
 
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.plc4x.java.ads.api.commands.types.TimeStamp;
+import org.apache.plc4x.java.api.exceptions.PlcProtocolException;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -36,7 +37,7 @@ public class LittleEndianEncoder {
         // Utility class
     }
 
-    public static byte[] encodeData(Class<?> valueType, Object[] values) {
+    public static byte[] encodeData(Class<?> valueType, Object[] values) throws PlcProtocolException {
         if (values.length == 0) {
             return new byte[]{};
         }
@@ -56,21 +57,25 @@ public class LittleEndianEncoder {
         } else if (valueType == String.class) {
             result = encodeString(Arrays.stream(values).map(String.class::cast));
         } else {
-            throw new IllegalArgumentException("Unsupported type" + valueType);
+            throw new PlcProtocolException("Unsupported datatype " + valueType);
         }
 
         // TODO: maybe we can replace this by a smarter flatmap
-        return result.collect(
-            ByteArrayOutputStream::new,
-            (bos, byteValue) -> {
-                try {
-                    bos.write(byteValue);
-                } catch (IOException e) {
-                    throw new RuntimeException(e);
-                }
-            },
-            (a, b) -> {
-            }).toByteArray();
+        try {
+            return result.collect(
+                ByteArrayOutputStream::new,
+                (bos, byteValue) -> {
+                    try {
+                        bos.write(byteValue);
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                },
+                (a, b) -> {
+                }).toByteArray();
+        } catch (RuntimeException e) {
+            throw new PlcProtocolException("Error encoding data", e);
+        }
     }
 
     public static Stream<byte[]> encodeString(Stream<String> stringStream) {

-- 
To stop receiving notification emails like this one, please contact
cdutz@apache.org.