Java Byte Array Dump dump(byte[] bytes)

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

Description

dump byte [] as StringBuilder "0x00, ..., 0xFF"

License

Open Source License

Declaration

public static StringBuilder dump(byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from w  w w .j  a v  a  2  s.co m*/
     * dump byte [] as StringBuilder  "0x00, ..., 0xFF"
     */
    public static StringBuilder dump(byte[] bytes) {
        if (bytes == null)
            throw new IllegalArgumentException("null bytes");
        return dump(bytes, 0, bytes.length);
    }

    public static StringBuilder dump(byte[] bytes, int offset, int length) {
        if (bytes == null)
            throw new IllegalArgumentException("null bytes");

        StringBuilder sbuf = new StringBuilder();
        int i, cnt = offset + length;
        for (i = offset; i < cnt; i++) {
            if (i > offset)
                sbuf.append(", ");
            sbuf.append("(byte)0x" + Integer.toHexString(((int) bytes[i]) & 0xFF).toUpperCase());
        }
        return sbuf;
    }
}

Related

  1. dump(byte b[])
  2. dump(byte[] array)
  3. dump(byte[] array)
  4. dump(byte[] buff, int size, boolean asBits)
  5. dump(byte[] buffer)
  6. dump(byte[] bytes, int offset, int byteslen)
  7. dump(byte[] data, int offset, int length)
  8. dump(byte[] data, int pos, int length)
  9. dump(byte[] mem, int start, int len)