Java XML Data Type Converter getByteListStr(List byteList, boolean isEncode)

Here you can find the source of getByteListStr(List byteList, boolean isEncode)

Description

get Byte List Str

License

Open Source License

Declaration

private static String getByteListStr(List byteList, boolean isEncode) throws Exception 

Method Source Code


//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;
    }
}

Related

  1. fromString(String s)
  2. fromStringSafe(final String s)
  3. generateSalt()
  4. generateSalt(int clientNonceByteCount)
  5. getByteList(String nomal, boolean isDecode)
  6. getDataUrlForBytes(final byte[] bytes)
  7. getImgurContent(String clientID, byte[] image)
  8. getLong(byte[] data)
  9. getText(URL url, String user, String password)