Android Byte Array to String Convert printBytes(byte[] data, String type)

Here you can find the source of printBytes(byte[] data, String type)

Description

print Bytes

Declaration

public static void printBytes(byte[] data, String type) 

Method Source Code

//package com.java2s;

public class Main {
    public static void printBytes(byte[] data, String type) {
        if (type == null) {
            type = "";
        }//  w ww. j av a2  s  .co m
        System.out.println();
        System.out.println(bytes2StringPtr(data, type));
        System.out.println();

    }

    public static String bytes2StringPtr(byte[] data, String type) {
        if (type == null) {
            type = "";
        }
        StringBuffer sb = new StringBuffer();
        System.out.println();
        for (int i = 0; i < data.length; i++) {
            sb.append(String.format("".equals(type) ? "0x%x," : type + ",",
                    data[i]));
        }
        return sb.toString();

    }

    public static byte[] append(byte[] data, byte[] adata) {
        if (data == null) {
            data = new byte[0];
        }
        int len = data.length;
        if (adata == null) {
            return data;
        }
        int alen = adata.length;

        byte[] result = new byte[(len + alen)];

        for (int i = 0, j = 0; i < len + alen; i++) {
            if (i < len) {
                result[i] = data[i];
                continue;
            }
            result[i] = adata[j];
            j++;
        }

        return result;

    }
}

Related

  1. toStringForm(byte[] arr)
  2. toStringUntil(byte[] b, int pos, byte until)
  3. toStringWithLength(byte[] b, int pos, int length)
  4. printBytes(byte[] bytes, StringBuilder builder, int bytesPerLine)
  5. printBytes(byte[] bytes, int bytesPerLine)
  6. bytesToByteString(byte[] bytes)
  7. toText(byte[] arr)
  8. byteArray(StringBuilder buffer, byte[] bytes)
  9. byteArrayToInt(byte[] value, int offset)