Java Byte Array Dump dump(byte b[])

Here you can find the source of dump(byte b[])

Description

dump

License

Open Source License

Declaration

public final static void dump(byte b[]) 

Method Source Code

//package com.java2s;
/** //from w w w.jav  a  2 s  .c  o  m
 * Copyright (c) 2003-2007 Stewart Allen <stewart@neuron.com>. All rights reserved.
 * This program is free software. See the 'License' file for details.
 */

public class Main {
    private final static byte hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
            'f' };

    public final static void dump(byte b[]) {
        dump(b, b.length);
    }

    public final static void dump(String prefix, byte b[]) {
        dump(prefix, b, b.length);
    }

    public final static void dump(byte b[], int len) {
        dump("+ ", b, len);
    }

    public final static void dump(String prefix, byte b[], int len) {
        len = Math.min(len, b.length);
        byte line[] = new byte[75];
        for (int i = 0; i < 75; i++) {
            line[i] = ' ';
        }
        for (int i = 0; i < len; i += 16) {
            for (int j = 0; j < 16; j++) {
                if (i + j < len) {
                    int d = b[i + j] & 0xff;
                    line[j * 3 + 0] = hex[d / 16];
                    line[j * 3 + 1] = hex[d % 16];
                    line[j * 3 + 2] = (byte) ' ';
                    line[j + 51] = (byte) (d >= 32 && d <= 126 ? d : '.');
                } else {
                    line[j * 3 + 0] = ' ';
                    line[j * 3 + 1] = ' ';
                    line[j * 3 + 2] = ' ';
                    line[j + 51] = ' ';
                }
            }
            System.out.println(prefix + new String(line));
        }
    }
}

Related

  1. dump(byte[] array)
  2. dump(byte[] array)
  3. dump(byte[] buff, int size, boolean asBits)
  4. dump(byte[] buffer)