package cd.casic.ci.process.util;

import org.apache.commons.io.IOUtils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class FileUtil {
    public static String getMD5Str(InputStream inputStream) throws NoSuchAlgorithmException, IOException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] buffer = new byte[1024];
        int len = -1;
        while((len=inputStream.read(buffer))!=-1){
            md.update(buffer,0,len);
        }
        byte[] digest = md.digest();
        StringBuilder stringBuilder = new StringBuilder();
        for (byte b : digest) {
            String format = String.format("%02x", b);
            stringBuilder.append(format);
        }
        return stringBuilder.toString();
    }
}
