package com.bocloud.ims.service.utils;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;

/**
 * @author 作者
 * @version 创建时间：2019年11月26日 下午5:24:29 类说明
 */
public class YamlUtil {

    private static Logger logger = LoggerFactory.getLogger(YamlUtil.class);

    public static String readToString(String fileName) throws Exception {
        try {
            ClassPathResource classPathResource = new ClassPathResource("static/" + fileName);
            InputStream inputStream = classPathResource.getInputStream();
            ByteArrayOutputStream result = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int length;
            while ((length = inputStream.read(buffer)) != -1) {
                result.write(buffer, 0, length);
            }
            return result.toString(StandardCharsets.UTF_8.name());
        } catch (Exception e) {
            logger.error("读取文件异常：" + e.getMessage());
            return null;
        }
    }

}
