Java Byte Array to String bytes2String(byte[] bytes)

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

Description

bytes String

License

Open Source License

Declaration

public static String bytes2String(byte[] bytes) 

Method Source Code

//package com.java2s;
/**/*w  w  w  .ja  v  a  2  s.  co  m*/
 * Copyright (c) 2012 Baozun All Rights Reserved.
 *
 * This software is the confidential and proprietary information of Baozun.
 * You shall not disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Baozun.
 *
 * BAOZUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE, OR NON-INFRINGEMENT. BAOZUN SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
 * THIS SOFTWARE OR ITS DERIVATIVES.
 *
 */

public class Main {
    private static final char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
            'F' };

    public static String bytes2String(byte[] bytes) {
        if (bytes == null || bytes.length == 0)
            return "";
        StringBuffer sb = new StringBuffer();
        for (byte b : bytes)
            sb.append(byte2HEX(b));
        return sb.toString();
    }

    public static String byte2HEX(byte ib) {
        char[] ob = new char[2];
        ob[0] = Digit[(ib >>> 4) & 0X0F];
        ob[1] = Digit[ib & 0X0F];
        String s = new String(ob);
        return s;
    }
}

Related

  1. bytes2Str(byte[] bytes, String separator)
  2. bytes2String(byte[] args)
  3. bytes2String(byte[] b, int start, int len)
  4. bytes2String(byte[] bs, String charset)
  5. bytes2String(byte[] buffer, int offset, int length)
  6. bytes2String(byte[] bytes)
  7. bytes2String(byte[] bytes)
  8. bytes2String(byte[] bytesArray)
  9. bytes2String(byte[] data)