package com.xjrsoft.common.utils;

import org.smartboot.license.client.License;
import org.smartboot.license.client.LicenseEntity;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * license 工具类
 *
 * @Author: tzx
 * @Date: 2023/6/30 8:23
 */
public class LicenseUtil {

    public static void loadLicense(Properties properties) {
        License license = new License();

        try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("License.shield")) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            byte[] bytes = new byte[1024];
            int size;
            while ((size = inputStream.read(bytes)) > 0) {
                byteArrayOutputStream.write(bytes, 0, size);
            }
            LicenseEntity entity = license.loadLicense(byteArrayOutputStream.toByteArray());

            properties.load(new ByteArrayInputStream(entity.getData()));

            System.out.println(properties);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
