blob: 96f87432a4fb96e2beefaaef054cd33a4ecc1f1f [file] [log] [blame]
Yuta HIGUCHIc9d06ef2014-01-31 15:55:12 -08001package net.onrc.onos.datastore.utils;
2
3import java.nio.ByteBuffer;
4
5public class ByteArrayUtil {
6
7 public static StringBuffer toHexStringBuffer(final byte[] bytes,
8 final String sep) {
9 return toHexStringBuffer(bytes, sep, new StringBuffer());
10 }
11
12 public static StringBuffer toHexStringBuffer(final byte[] bytes,
13 final String sep, StringBuffer buf) {
14 if (bytes == null) {
15 return buf;
16 }
17
18 ByteBuffer wrap = ByteBuffer.wrap(bytes);
19
20 boolean hasWritten = false;
21 while (wrap.hasRemaining()) {
22 if (hasWritten) {
23 buf.append(sep);
24 }
25 buf.append(Integer.toHexString(wrap.get()));
26 hasWritten = true;
27 }
28
29 return buf;
30 }
31}