Here you can find the source of ToByteArrayString(byte[] bytes)
public static String ToByteArrayString(byte[] bytes)
//package com.java2s; public class Main { public static String ToByteArrayString(byte[] bytes) { if (bytes == null) { return "null"; }/*from w ww. ja v a 2s. c om*/ StringBuilder sb = new StringBuilder(); String hex = "0123456789ABCDEF"; sb.append("new byte[] { "); for (int i = 0; i < bytes.length; ++i) { if (i > 0) { sb.append(", "); } if ((bytes[i] & 0x80) != 0) { sb.append("(byte)0x"); } else { sb.append("0x"); } sb.append(hex.charAt((bytes[i] >> 4) & 0xf)); sb.append(hex.charAt(bytes[i] & 0xf)); } sb.append("}"); return sb.toString(); } }