summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/io/HexDump.java
diff options
context:
space:
mode:
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/io/HexDump.java')
-rw-r--r--vespajlib/src/main/java/com/yahoo/io/HexDump.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/io/HexDump.java b/vespajlib/src/main/java/com/yahoo/io/HexDump.java
new file mode 100644
index 00000000000..65a6f8d2b5a
--- /dev/null
+++ b/vespajlib/src/main/java/com/yahoo/io/HexDump.java
@@ -0,0 +1,27 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.io;
+
+/**
+ * @author bratseth
+ */
+public class HexDump {
+
+ private static final String HEX_CHARS = "0123456789ABCDEF";
+
+ public static String toHexString(byte[] buf) {
+ if (buf == null) {
+ return null;
+ }
+ StringBuilder sb = new StringBuilder();
+ for (byte b : buf) {
+ int x = b;
+ if (x < 0) {
+ x += 256;
+ }
+ sb.append(HEX_CHARS.charAt(x / 16));
+ sb.append(HEX_CHARS.charAt(x % 16));
+ }
+ return sb.toString();
+ }
+
+}