diff options
Diffstat (limited to 'java/common/src/main/java/org/apache/qpid/transport/util/Functions.java')
-rw-r--r-- | java/common/src/main/java/org/apache/qpid/transport/util/Functions.java | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/transport/util/Functions.java b/java/common/src/main/java/org/apache/qpid/transport/util/Functions.java index bd3e9bbcbc..61d5f0629c 100644 --- a/java/common/src/main/java/org/apache/qpid/transport/util/Functions.java +++ b/java/common/src/main/java/org/apache/qpid/transport/util/Functions.java @@ -20,10 +20,10 @@ */ package org.apache.qpid.transport.util; -import java.nio.ByteBuffer; - import static java.lang.Math.min; +import java.nio.ByteBuffer; + /** * Functions @@ -33,6 +33,9 @@ import static java.lang.Math.min; public final class Functions { + private static final char[] HEX_CHARACTERS = + {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + private Functions() { } @@ -102,4 +105,21 @@ public final class Functions return str(ByteBuffer.wrap(bytes), limit); } + public static String hex(byte[] bytes, int limit) + { + limit = Math.min(limit, bytes == null ? 0 : bytes.length); + StringBuilder sb = new StringBuilder(3 + limit*2); + for(int i = 0; i < limit; i++) + { + sb.append(HEX_CHARACTERS[(((int)bytes[i]) & 0xf0)>>4]); + sb.append(HEX_CHARACTERS[(((int)bytes[i]) & 0x0f)]); + + } + if(bytes != null && bytes.length>limit) + { + sb.append("..."); + } + return sb.toString(); + } + } |