Guest User

Untitled

a guest
Jul 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import java.io.File;
  2. import java.math.BigInteger;
  3. import java.nio.file.Files;
  4. import java.security.MessageDigest;
  5.  
  6. import org.zeroturnaround.zip.ZipUtil;
  7.  
  8. public class ZipUtilPackMd5 {
  9. public static void main(String[] args) throws Exception {
  10. String fileName = "target/classes/ZipUtilPackMd5.class";
  11. File file = new File(fileName);
  12. if (!file.exists())
  13. throw new RuntimeException(fileName + " does not exist");
  14.  
  15. byte[] bytes = Files.readAllBytes(file.toPath());
  16. System.out.println("Input file " + md5(bytes));
  17.  
  18. byte[] zippedBytes = ZipUtil.packEntry(file);
  19. System.out.println(md5(zippedBytes));
  20. zippedBytes = ZipUtil.packEntry(file);
  21. System.out.println(md5(zippedBytes));
  22. }
  23.  
  24. private static String md5(byte[] bytes) throws Exception {
  25. MessageDigest m = MessageDigest.getInstance("MD5");
  26. m.update(bytes, 0, bytes.length);
  27. return "md5: " + new BigInteger(1, m.digest()).toString(16);
  28. }
  29. }
Add Comment
Please, Sign In to add comment