Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.math.BigInteger;
- import java.nio.file.Files;
- import java.security.MessageDigest;
- import org.zeroturnaround.zip.ZipUtil;
- public class ZipUtilPackMd5 {
- public static void main(String[] args) throws Exception {
- String fileName = "target/classes/ZipUtilPackMd5.class";
- File file = new File(fileName);
- if (!file.exists())
- throw new RuntimeException(fileName + " does not exist");
- byte[] bytes = Files.readAllBytes(file.toPath());
- System.out.println("Input file " + md5(bytes));
- byte[] zippedBytes = ZipUtil.packEntry(file);
- System.out.println(md5(zippedBytes));
- zippedBytes = ZipUtil.packEntry(file);
- System.out.println(md5(zippedBytes));
- }
- private static String md5(byte[] bytes) throws Exception {
- MessageDigest m = MessageDigest.getInstance("MD5");
- m.update(bytes, 0, bytes.length);
- return "md5: " + new BigInteger(1, m.digest()).toString(16);
- }
- }
Add Comment
Please, Sign In to add comment