Here you can find the source of getByteListStr(List byteList, boolean isEncode)
private static String getByteListStr(List byteList, boolean isEncode) throws Exception
//package com.java2s; //License from project: Open Source License import javax.xml.bind.DatatypeConverter; import java.util.List; public class Main { private static final String CHARACTER_SET = "UTF-8"; private static String getByteListStr(List byteList, boolean isEncode) throws Exception { byte[] listByte = new byte[byteList.size() * 16]; for (int i = 0; i < byteList.size(); i++) { byte[] temp = (byte[]) byteList.get(i); for (int j = 0; j < temp.length; j++) { listByte[j + (16 * i)] = temp[j]; }/*from www . j a v a 2s . com*/ } int blankCnt = 0; for (int i = listByte.length; i > 0; i--) { if (listByte[i - 1] == 0) { blankCnt++; } else { break; } } byte[] resultByte = new byte[listByte.length - blankCnt]; for (int i = 0; i < resultByte.length; i++) { resultByte[i] = listByte[i]; } String retStr = null; if (isEncode) { retStr = DatatypeConverter.printBase64Binary(resultByte); } else { retStr = new String(resultByte, CHARACTER_SET); } return retStr; } }