package com.hz.pm.api.performance.util;

/**
 * @author CMM
 * @since 2023/08/17 21:02
 */

import cn.hutool.core.util.CharsetUtil;
import com.ningdatech.basic.exception.BizException;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Content-type 工具类
 * @return
 * @author CMM
 * @since 2023/08/17 21:05
 */
public final class ContentTypeUtils {

    private ContentTypeUtils() {
    }

    public static final String CONTENT_DISPOSITION;
    public static final String APPLICATION_EXCEL;
    static {
        CONTENT_DISPOSITION = "Content-Disposition";
        APPLICATION_EXCEL = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    }
    public static String encode(String fileName) {

        try {
            return "attachment;filename=" + URLEncoder.encode(fileName, CharsetUtil.UTF_8) + ".xlsx";
        } catch (UnsupportedEncodingException e) {
            throw new BizException(e.getMessage());
        }
    }
}

