public static byte[] hashFile(File file) throws IOException { synchronized (DIGEST) { DIGEST.reset(); updateDigest(DIGEST, file); return DIGEST.digest(); } }
public static byte[] hashFile(File file) throws IOException { synchronized (DIGEST) { DIGEST.reset(); updateDigest(DIGEST, file); return DIGEST.digest(); } }
private static void updateDigest(MessageDigest digest, File file) throws IOException { if (file.isDirectory()) { File[] childList = file.listFiles(); if (childList != null) { Map<String, File> sortedChildren = new TreeMap<String, File>(); for (File child : childList) { sortedChildren.put(child.getName(), child); } for (File child : sortedChildren.values()) { updateDigest(digest, child); } } } else { // jar index files are generated by JBoss modules at runtime (a pristine AS7 installation does not have them). // they are skipped when computing checksum to avoid different checksum for the same JBoss module depending on // whether the AS7 installation has been started or not. if (file.getName().endsWith(".jar.index")) { return; } try (FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis)){ byte[] bytes = new byte[8192]; int read; while ((read = bis.read(bytes)) > -1) { digest.update(bytes, 0, read); } } } }
private static void updateDigest(MessageDigest digest, File file) throws IOException { if (file.isDirectory()) { File[] childList = file.listFiles(); if (childList != null) { Map<String, File> sortedChildren = new TreeMap<String, File>(); for (File child : childList) { sortedChildren.put(child.getName(), child); } for (File child : sortedChildren.values()) { updateDigest(digest, child); } } } else { // jar index files are generated by JBoss modules at runtime (a pristine AS7 installation does not have them). // they are skipped when computing checksum to avoid different checksum for the same JBoss module depending on // whether the AS7 installation has been started or not. if (file.getName().endsWith(".jar.index")) { return; } try (FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis)){ byte[] bytes = new byte[8192]; int read; while ((read = bis.read(bytes)) > -1) { digest.update(bytes, 0, read); } } } }