Here you can find the source of bytesToHexStringLine(byte[] bs, int lineLength)
public static String bytesToHexStringLine(byte[] bs, int lineLength)
//package com.java2s; //License from project: Apache License public class Main { private static final char[] hex = "0123456789ABCDEF".toCharArray(); public static String bytesToHexStringLine(byte[] bs, int lineLength) { if (bs == null || bs.length == 0) { return ""; }/*ww w . j av a 2 s . c o m*/ StringBuffer str = new StringBuffer(bs.length * 4); for (int i = 0; i < bs.length; i++) { str.append(hex[(bs[i] >> 4) & 0x0f]); str.append(hex[bs[i] & 0x0f]); if (i > 0 && i % lineLength == lineLength - 1) { str.append("\r\n"); } else { str.append(" "); } } return str.toString(); } }