Java XML Data Type Converter getByteList(String nomal, boolean isDecode)

Here you can find the source of getByteList(String nomal, boolean isDecode)

Description

seed 128bit

License

Open Source License

Declaration

private static List<byte[]> getByteList(String nomal, boolean isDecode) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.xml.bind.DatatypeConverter;
import java.util.ArrayList;
import java.util.List;

public class Main {
    private static final String CHARACTER_SET = "UTF-8";

    /**/*from  www . j a va  2s .  c o m*/
     * seed 128bit
     */
    private static List<byte[]> getByteList(String nomal, boolean isDecode) throws Exception {

        List<byte[]> byteList = new ArrayList<byte[]>();

        byte[] tempByte = null;

        if (isDecode) {
            tempByte = DatatypeConverter.parseBase64Binary(nomal);
        } else {
            tempByte = nomal.getBytes(CHARACTER_SET);
        }

        int needBlankLength = 0;
        if (tempByte.length % 16 != 0) {
            needBlankLength = 16 - (tempByte.length % 16);
        }

        byte[] newTempByte = new byte[tempByte.length + needBlankLength];

        for (int i = 0; i < tempByte.length; i++) {
            newTempByte[i] = tempByte[i];
        }

        int inListByteIdx = 0;
        byte[] inListByte = new byte[16];
        for (int i = 0; i < newTempByte.length; i++) {

            inListByte[inListByteIdx] = newTempByte[i];
            inListByteIdx++;

            if ((i + 1) % 16 == 0 && i != 0) {
                byteList.add(inListByte);
                inListByte = new byte[16];
                inListByteIdx = 0;
            }
        }

        return byteList;
    }
}

Related

  1. formatFriendlyName(final byte[] addressBytes)
  2. fromString(String s)
  3. fromStringSafe(final String s)
  4. generateSalt()
  5. generateSalt(int clientNonceByteCount)
  6. getByteListStr(List byteList, boolean isEncode)
  7. getDataUrlForBytes(final byte[] bytes)
  8. getImgurContent(String clientID, byte[] image)
  9. getLong(byte[] data)