Java Hex Dump hexDumpBytes(PrintStream out, long offset, byte[] bytes)

Here you can find the source of hexDumpBytes(PrintStream out, long offset, byte[] bytes)

Description

hex Dump Bytes

License

Open Source License

Declaration

public static void hexDumpBytes(PrintStream out, long offset, byte[] bytes) 

Method Source Code

//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));
        }
    }
}

Related

  1. hexDump(byte[] data)
  2. hexDump(InputStream is, OutputStream os)
  3. hexDump(InputStream is, PrintStream ps, int maxRead, int bytesPerLine)
  4. hexDump(PrintStream out, String s, byte b[], int n)
  5. hexDump(String prompt, byte[] bs)