Merge "BUG 5746 - Ovsdb QoS and Queue model enhancements"
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / ovsdb / transact / TransactUtils.java
index 0877ac8459f2f1e64b3a021e71cb1f21f3d9432e..c5e565a2d53add51b093741c64ca96342dd92ef4 100644 (file)
@@ -484,4 +484,41 @@ public class TransactUtils {
         mutate.setMutations(mutations);
         return mutate;
     }
+
+    /**
+     * This method builds a string by concatenating the 2 character
+     * hexadecimal representation of each byte from the input byte array.
+     *
+     * For example: an input byte array containing:
+     *   bytes[0] = 'a'
+     *   bytes[1] = 'b'
+     *   bytes[2] = 'c'
+     *   bytes[3] = '-'
+     *   bytes[4] = '1'
+     *   bytes[5] = '2'
+     *   bytes[6] = '3'
+     * returns the string "6162632d313233"
+     *
+     * @param bytes
+     *            The byte array to convert to string
+     * @return The hexadecimal representation of the byte array. If bytes is
+     *         null, the string "" is returned
+     */
+    public static String bytesToHexString(byte[] bytes) {
+
+        if (bytes == null) {
+            return "";
+        }
+
+        StringBuffer buf = new StringBuffer();
+        for (int i = 0; i < bytes.length; i++) {
+            short u8byte = (short) (bytes[i] & 0xff);
+            String tmp = Integer.toHexString(u8byte);
+            if (tmp.length() == 1) {
+                buf.append("0");
+            }
+            buf.append(tmp);
+        }
+        return buf.toString();
+    }
 }