Here you can find the source of hexDumpBytes(PrintStream out, long offset, byte[] bytes)
public static void hexDumpBytes(PrintStream out, long offset, byte[] bytes)
//package com.java2s; //License from project: Open Source License import java.io.PrintStream; public class Main { private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); public static void hexDumpBytes(PrintStream out, long offset, byte[] bytes) { final int lineWidth = 16; char[] line = new char[lineWidth * 3]; for (int i = 0; i < bytes.length; i += lineWidth) { int len = Math.min(bytes.length - i, 16); for (int j = 0; j < len; j++) { int value = bytes[i + j] & 0xFF; line[j * 3 + 0] = hexArray[value >>> 4]; line[j * 3 + 1] = hexArray[value & 0x0F]; line[j * 3 + 2] = ' '; }//w w w. jav a2 s . co m int len1 = Math.min(len, 8) * 3; int len2 = Math.min(len - 8, 8) * 3; out.printf("0x%08X: %s %s%n", offset + (long) i, new String(line, 0, len1), new String(line, 8 * 3, len2)); } } }