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

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

Description

bytes String

Declaration

public static String bytes2String(byte[] data, String type) 

Method Source Code

//package com.java2s;

public class Main {
    public static String bytes2String(byte[] data, String type) {
        if (type == null) {
            type = "";
        }/*  w ww.  j a  v a  2s . co m*/
        StringBuffer sb = new StringBuffer();
        System.out.println();
        for (int i = 0; i < data.length; i++) {
            if ("".equals(type)) {
                sb.append(String.format("%02x", data[i]));
            } else {
                sb.append(String.format(type + "%02x", 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. ByteArrayToString(byte[] input)
  2. byteArrayToString(byte[] b)
  3. byteArrayToString(byte[] bytes)
  4. byteToString(byte b)
  5. bytes2String(byte[] data)
  6. bytes2StringPtr(byte[] data, String type)
  7. getString(byte[] bb)
  8. getString(byte[] bytes)
  9. getString(byte[] bytes, String charsetName)