ZipUtils { public static ZipResult createZipAndCheck(File srcFolder, File destFolder, String zipName, boolean compress) { if(zipName==null) { zipName = srcFolder.getName(); } File newZipFile = createZip(srcFolder, destFolder, zipName, compress); log.info("[createZipAndCheck] Zip file created: " + zipName); ZipResult zipResult = new ZipResult(); try { byte[] digest = Checksums.md5(newZipFile); zipResult.setZipFile(newZipFile); zipResult.setChecksum(new Checksum("MD5", Arrays.toString(digest))); log.info("[createZipAndCheck] Checksum (MD5) created: " + zipResult.getChecksum()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return zipResult; }  static File createZip(File srcFolder, File destFolder, String zipName, boolean compress); static ZipResult createZipAndCheck(File srcFolder, File destFolder, String zipName, boolean compress); @SuppressWarnings("unchecked") static List<File> unzipTo(File zipFile, File destFolder); static List<File> checkAndUnzipTo(File zipFile, File destFolder, Checksum checksum); static String[] getAllFragments(File zip); static File getFileFrom(File zip, String targetPathInZipfile, File destFolder); static File insertFileInto(File zipFile, File toInsert, String targetPath); static File removeFileFrom(File zipFile, String fileToRemove); @SuppressWarnings("unchecked") static boolean isZipFile(File file); @SuppressWarnings("unchecked") static List<String> listZipEntries(File zip);  }
@Test public void testCreateZipFileWithChecksum() { File[] files = TEST_FILE_FOLDER.listFiles(); System.out.println("File count: " + files.length); for (int i = 0; i < files.length; i++) { System.out.println(i + ": " + files[i].getAbsolutePath()); } ZipResult zipResult = ZipUtils.createZipAndCheck( TEST_FILE_FOLDER, outputFolder, DigitalObjectUtils.randomizeFileName(TEST_FILE_FOLDER.getName() + ".zip"), false); File zip = zipResult.getZipFile(); System.out.println("Please find ZIP here: " + zip.getAbsolutePath()); System.out.println("Zip Checksum is: " + zipResult.getChecksum()); }