private String sha2Of(File file) {
if (file.length() > Integer.MAX_VALUE >> 2) {
return sha2OfBigger(file);
}
try (FileChannel ch = new FileInputStream(file).getChannel()) {
byte[] arry = new byte[1024 * 8];
ByteBuffer byteBuffer = ByteBuffer.wrap(arry);
int size = ch.read(byteBuffer);
MessageDigest sha2 = MessageDigest.getInstance("SHA-256");
while (size != -1) {
sha2.update(arry, 0, size);
byteBuffer.rewind();
size = ch.read(byteBuffer);
}
return new HexBinaryAdapter().marshal(sha2.digest());
} catch (IOException | NoSuchAlgorithmException e) {
e.printStackTrace();
return "\\";
}
}
DuplicatedFiles.java 文件源码
java
阅读 24
收藏 0
点赞 0
评论 0
项目:KeepTry
作者:
评论列表
文章目录