Java Byte Array Dump dump(byte[] mem, int start, int len)

Here you can find the source of dump(byte[] mem, int start, int len)

Description

dump

License

Open Source License

Declaration

public static final void dump(byte[] mem, int start, int len) 

Method Source Code

//package com.java2s;
/* Cortado - a video player java applet
 * Copyright (C) 2004 Fluendo S.L./*from  w w w  .  j  a  v a  2s.c  o m*/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
 */

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

    public static final void dump(byte[] mem, int start, int len) {
        int i, j;
        StringBuffer string = new StringBuffer(50);
        StringBuffer chars = new StringBuffer(18);
        String vis = new String(mem, start, len);

        i = j = 0;
        while (i < len) {
            int b = ((int) mem[i + start]);
            if (b < 0)
                b += 256;

            if (b > 0x20 && b < 0x7f)
                chars.append(vis.charAt(i));
            else
                chars.append(".");

            string.append(bytes[b / 16]);
            string.append(bytes[b % 16]);
            string.append(" ");

            j++;
            i++;

            if (j == 16 || i == len) {
                System.out.println("" + (i - j) + "  " + string.toString() + chars.toString());

                string.setLength(0);
                chars.setLength(0);
                j = 0;
            }
        }
    }
}

Related

  1. dump(byte[] buffer)
  2. dump(byte[] bytes)
  3. dump(byte[] bytes, int offset, int byteslen)
  4. dump(byte[] data, int offset, int length)
  5. dump(byte[] data, int pos, int length)
  6. dump(byte[] rec)
  7. dump(byte[] str)
  8. dumpArray(byte b[])
  9. dumpArray(byte[] b)