Java MD5 String md5(File gcdZipFile)

Here you can find the source of md5(File gcdZipFile)

Description

md

License

Open Source License

Declaration

private static String md5(File gcdZipFile) throws IOException 

Method Source Code


//package com.java2s;
/*/* www  . j a va  2 s  .  c  o m*/
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.BufferedInputStream;

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStream;

import java.math.BigInteger;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    private static String md5(File gcdZipFile) throws IOException {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            try (InputStream is = new BufferedInputStream(new FileInputStream(gcdZipFile))) {
                byte[] bytes = new byte[4 * 1024 * 1024];
                int len;
                while ((len = is.read(bytes)) >= 0) {
                    md5.update(bytes, 0, len);
                }
            }
            return String.format("%032x", new BigInteger(1, md5.digest()));
        } catch (NoSuchAlgorithmException e) {
            throw new IOException(e);
        }
    }
}

Related

  1. md5(File f)
  2. md5(File f)
  3. md5(File file)
  4. md5(File file)
  5. md5(File file)
  6. md5(final File file)
  7. md5(final InputStream in)
  8. md5(final String data)
  9. md5(final String inData)