package com.zksy.audio.utils;

import cn.hutool.core.util.StrUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.stream.Collectors;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CrtHelper {

    public static String byteToHexStr1(byte[] bytes) {
        String returnStr = "";
        if (bytes != null) {
            for (int i = 0; i < bytes.length; i++) {
                returnStr += String.format("%02X", bytes[i]);

            }
        }
        return returnStr;
    }

    public static byte[] strToToHexByte1(String hexString) {
        hexString = hexString.replaceAll(" ", "");
        if ((hexString.length() % 2) != 0) {
            hexString += " ";
        }
        byte[] returnBytes = new byte[hexString.length() / 2];
        for (int i = 0; i < returnBytes.length; i++) {
            int pos = i * 2;

            returnBytes[i] = (byte) Integer.parseInt(StrUtil.sub(hexString, pos, pos + 2), 16);
        }
        return returnBytes;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.stream(Arrays.toString(strToToHexByte1("242424323032343131303031300D0A")).split(",")).collect(Collectors.joining("")));
    }

}
