将byte数组变为16进制对应的字符串

@param byteArray byte数组
@return 转换结果
194447
private static String byteToStr(byte[] byteArray) {
        int len = byteArray.length;
        StringBuilder strDigest = new StringBuilder(len * 2);
        for (byte aByteArray : byteArray) {
            strDigest.append(byteToHexStr(aByteArray));
        }
        return strDigest.toString();
    }
548890
public boolean load(ByteArray byteArray)
    {
        if (byteArray == null) return false;
        model_header = byteArray.nextString();
        root = byteArray.nextString();

        use_distance = byteArray.nextInt() == 1;
        use_valency = byteArray.nextInt() == 1;
        use_cluster = byteArray.nextInt() == 1;

        W1 = new Matrix();
        W1.load(byteArray);
        W2 = new Matrix();
        W2.load(byteArray);
        E = new Matrix();
        E .load(byteArray);
        b1 = new Matrix();
        b1 .load(byteArray);
        saved = new Matrix();
        saved .load(byteArray);

        forms_alphabet = new Alphabet();
        forms_alphabet .load(byteArray);
        postags_alphabet = new Alphabet();
        postags_alphabet .load(byteArray);
        deprels_alphabet = new Alphabet();
        deprels_alphabet .load(byteArray);

        precomputation_id_encoder = read_map(byteArray);

        if (use_cluster)
        {
            cluster4_types_alphabet = new Alphabet();
            cluster4_types_alphabet.load(byteArray);
            cluster6_types_alphabet = new Alphabet();
            cluster6_types_alphabet .load(byteArray);
            cluster_types_alphabet = new Alphabet();
            cluster_types_alphabet .load(byteArray);

            form_to_cluster4 = read_map(byteArray);
            form_to_cluster6 = read_map(byteArray);
            form_to_cluster = read_map(byteArray);
        }

        assert !byteArray.hasMore() : "文件有残留，可能是读取逻辑不对";

        classifier = new NeuralNetworkClassifier(W1, W2, E, b1, saved, precomputation_id_encoder);
        classifier.canonical();

        return true;
    }
328910
private static int byteArrayToInt(byte[] data)
    {
        // byte[] -> int
        int number = 0;
        for (int i = 0; i < 4; ++i)
        {
            number |= (data[3-i] & 0xff) << (i << 3);
        }
        return number;
    }
735815
public static byte[] toByteArray(final int i)
        {
        final byte[] b = new byte[4];

        b[0] = (byte) ((i & 0xff000000) >>> 24);
        b[1] = (byte) ((i & 0x00ff0000) >>> 16);
        b[2] = (byte) ((i & 0x0000ff00) >>> 8);
        b[3] = (byte) ((i & 0x000000ff));

        return b;
        }
594236
static public int asInt(byte[] array) {

        if (null == array || 4 != array.length) {
            throw new IllegalArgumentException("Length of the byte array should be 4");
        }

        return ((array[0] << 24)
                + ((array[1] & 255) << 16)
                + ((array[2] & 255) << 8) + (array[3] & 255));
    }
920534
public static String fromByteArray(byte[] ba) {
        if ((ba != null) && (ba.length == 16)) {
            StringBuilder result = new StringBuilder(36);
            for (int i = 0; i < 16; ++i) {
                if ((i == 4) || (i == 6) || (i == 8) || (i == 10)) {
                    result.append('-');
                }
                result.append(hexChars.charAt(((ba[i] & 0xF0) >>> 4)));
                result.append(hexChars.charAt((ba[i] & 0xF)));
            }
            return result.toString();
        }
        return null;
    }
383876
private static String byteToHexString(byte[] bytes)
  {
    final char[] hexArray = "0123456789ABCDEF".toCharArray();
    char[] hexChars = new char[bytes.length * 2];
    for (int j = 0; j < bytes.length; j++)
    {
      int v = bytes[j] & 0xFF;
      hexChars[j * 2] = hexArray[v >>> 4];
      hexChars[j * 2 + 1] = hexArray[v & 0x0F];
    }
    return new String(hexChars);
  }
1169116
public static String sum(byte[] bytes) {
    String result = "";
    for (byte b : bytes) {
      result += Integer.toString((b & 0xff) + 0x100, 16).substring(1);
    }
    return result;
  }
1038740
public static byte searchMax(byte[] byteArray) {
        if(byteArray.length == 0) {
            throw new IllegalArgumentException("The array you provided does not have any elements");
        }

        byte max = byteArray[0];

        for(int i = 1; i < byteArray.length; i++) {
            if(byteArray[i] > max) {
                max = byteArray[i];
            }
        }

        return max;
    }
697145
public static long getLongLE(final byte[] array, final int offset) {
    return  ( array[offset    ] & 0XFFL       )
          | ((array[offset + 1] & 0XFFL) <<  8)
          | ((array[offset + 2] & 0XFFL) << 16)
          | ((array[offset + 3] & 0XFFL) << 24)
          | ((array[offset + 4] & 0XFFL) << 32)
          | ((array[offset + 5] & 0XFFL) << 40)
          | ((array[offset + 6] & 0XFFL) << 48)
          | ((array[offset + 7] & 0XFFL) << 56);
  }
910622
private static String byteArrayToHexString(byte[] b)
	{
		StringBuilder sb = new StringBuilder(b.length * 2);
		for (int i = 0; i < b.length; i++)
		{
			int v = b[i] & 0xff;
			if (v < 16)
			{
				sb.append('0');
			}
			sb.append(Integer.toHexString(v));
		}
		return sb.toString().toUpperCase();
	}
1044331
public static int bytesToInt(byte[] b)
    {
        int i = (b[0] << 24) & 0xFF000000;
        i |= (b[1] << 16) & 0xFF0000;
        i |= (b[2] << 8) & 0xFF00;
        i |= b[3] & 0xFF;
        return i;
    }
1282654
public static byte[] decodeHex(final char[] hexDatas) {
        if (hexDatas.length % 2 != 0) {
            throw new IllegalArgumentException("非法的16进制字符");
        }
        byte[] data = new byte[hexDatas.length >> 1];
        for (int i = 0; i < hexDatas.length; i += 2) {
            data[i >> 1] = (byte) ((indexAt((byte) hexDatas[i]) << 4)
                                   | indexAt((byte) hexDatas[i + 1]));
        }
        return data;
    }
969276
public static long bytesToLong(byte[] b)
    {
        long l = ((long) b[0] << 56) & 0xFF00000000000000L;
        // 如果不强制转换为long，那么默认会当作int，导致最高32位丢失
        l |= ((long) b[1] << 48) & 0xFF000000000000L;
        l |= ((long) b[2] << 40) & 0xFF0000000000L;
        l |= ((long) b[3] << 32) & 0xFF00000000L;
        l |= ((long) b[4] << 24) & 0xFF000000L;
        l |= ((long) b[5] << 16) & 0xFF0000L;
        l |= ((long) b[6] << 8) & 0xFF00L;
        l |= (long) b[7] & 0xFFL;
        return l;
    }
453538
public static double byteArrayToDoubleLE( byte[] data ) {
        ByteBuffer buffer = ByteBuffer.wrap(data);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        return buffer.getDouble();
    }
272601
public static int byteArrayToInt(byte[] b, int offset) {
        int value = 0;
        for (int i = 0; i < 4; i++) {
            int shift = (4 - 1 - i) * 8;
            value += (b[i + offset] & 0x000000FF) << shift;
}
        return value;
    }
111085
public static byte[] removeNullBytes(byte[] array) {
		ByteArrayOutputStream baos = new ByteArrayOutputStream(array.length);
		for (byte b : array) {
			if (b != 0x00) {
				baos.write(b);
			}
		}
		return baos.toByteArray();
	}