Feat: cache md5 file value

This commit is contained in:
Laurent Clouet
2023-01-04 17:08:35 +01:00
parent 915884b855
commit 53782c43fd
2 changed files with 64 additions and 15 deletions

View File

@@ -68,21 +68,8 @@ public class Utils {
}
public static String md5(String path_of_file_) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
InputStream is = Files.newInputStream(Paths.get(path_of_file_));
DigestInputStream dis = new DigestInputStream(is, md);
byte[] buffer = new byte[8192];
while (dis.read(buffer) > 0)
; // process the entire file
String data = convertBinaryToHex(md.digest());
dis.close();
is.close();
return data;
}
catch (NoSuchAlgorithmException | IOException e) {
return "";
}
Md5 md5 = new Md5();
return md5.get(path_of_file_);
}
public static String convertBinaryToHex(byte[] bytes) {