Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame] | 1 | package net.onrc.onos.datastore.utils; |
| 2 | |
| 3 | import java.nio.ByteBuffer; |
| 4 | |
| 5 | public 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 | } |