package net.minecraft;

import java.io.*;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.util.Formatter;

public class Hash
{

    public Hash()
    {
    }

    public static String calculateHash(MessageDigest messagedigest, String s)
        throws Exception
    {
        FileInputStream fileinputstream = new FileInputStream(s);
        BufferedInputStream bufferedinputstream = new BufferedInputStream(fileinputstream);
        DigestInputStream digestinputstream = new DigestInputStream(bufferedinputstream, messagedigest);
        while(digestinputstream.read() != -1) ;
        byte abyte0[] = messagedigest.digest();
        return byteArray2Hex(abyte0);
    }

    private static String byteArray2Hex(byte abyte0[])
    {
        Formatter formatter = new Formatter();
        byte abyte1[] = abyte0;
        int i = abyte1.length;
        for(int j = 0; j < i; j++)
        {
            byte byte0 = abyte1[j];
            formatter.format("%02x", new Object[] {
                Byte.valueOf(byte0)
            });
        }

        return formatter.toString();
    }
}
