package com.yunjian.build.machine.constant;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
/**
* Base64文字转换工具类.
*
* @author Yuqisesn
* @since 2019/11/13
*/
public final class Base64Helper {
/** 日志控件 */
private static Logger LOG = LoggerFactory.getLogger(Base64Helper.class);
/**
* 读取输入流转化为Base64文字.
* @param stream 文件输入流
* @return Base64文字
*/
public static String streamToString(InputStream stream) {
byte[] data = null;
try {
data = new byte[stream.available()];
int size = stream.read(data);
stream.close();
if (size > 0) {
return encodeBase64String(data);
}
} catch (IOException e) {
LOG.error("Error in stream to base64 string!", e);
}
Base64编码解码工具类
猜你喜欢
转载自blog.csdn.net/weixin_42759398/article/details/131466430
今日推荐
周排行