Fixed issues
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / ByteBufUtils.java
index 80b818e01e1b89aedbd09592628d584f10b807ac..192d546fb10a202b22a934a4969f1a1c1d624c80 100644 (file)
@@ -201,23 +201,15 @@ public abstract class ByteBufUtils {
     }
     
     /**
-     * Reads and parses port name from ByteBuf
+     * Reads and parses null-terminated string from ByteBuf
      * @param rawMessage
      * @param length maximal length of String
      * @return String with name of port
      */
     public static String decodeNullTerminatedString(ByteBuf rawMessage, int length) {
-        byte[] name = new byte[EncodeConstants.MAX_PORT_NAME_LENGTH];
+        byte[] name = new byte[length];
         rawMessage.readBytes(name);
-        int index = 0;
-        for (int i = 0; i < name.length; i++) {
-            if (name[i] != 0) {
-                index++;
-            } else {
-                break;
-            }
-        }
-        byte[] correctName = Arrays.copyOf(name, index);
-        return new String(correctName);
+        return new String(name).trim();
     }
+    
 }