public static String checksum( String fileLocation , int algorithm )
    {

        String alg = null;

        switch ( algorithm ) {
            case Constants.CHECKSUM_ALG_MD_2: alg = "MD-2"; break;
            case Constants.CHECKSUM_ALG_MD_5: alg = "MD-5";  break;
            case Constants.CHECKSUM_ALG_SHA_1: alg = "SHA-1"; break;
            case Constants.CHECKSUM_ALG_SHA_256: alg = "SHA-256"; break;
            case Constants.CHECKSUM_ALG_SHA_384: alg = "SHA-384"; break;
            case Constants.CHECKSUM_ALG_SHA_512: alg = "SHA-512"; break;

            default: throw new IllegalArgumentException("Invalid checksum algorithm specified ( " + algorithm + " )");
        }

        try {
            MessageDigest md = MessageDigest.getInstance(alg);

            FileInputStream fis = new FileInputStream(fileLocation);

            byte[] dataBytes = new byte[16384];

            int nread = 0;
            while ((nread = fis.read(dataBytes)) != -1) {
              md.update(dataBytes, 0, nread);
            }

            byte[] mdbytes = md.digest();

            StringBuilder hexString = new StringBuilder();
            for (int i=0;i<mdbytes.length;i++) {
              hexString.append(Integer.toHexString(0xFF & mdbytes[i]));
            }

            return hexString.toString();

        } catch ( Exception ex ) {
            ex.printStackTrace();
        }

        return null;
    }