/**
* Calculate and return the sha1 sum of an input stream
*
* @param in the input stream to calculate the sha1 sum of
*
* @return the sha1 sum
*
* @throws IOException if there was an error calculating the sha1 sum
*/
public static String calculateSha1(InputStream in) throws IOException {
MessageDigest messageDigest;
InputStream inputStream = null;
try {
messageDigest = MessageDigest.getInstance("SHA-1");
inputStream = new BufferedInputStream(in);
byte[] buffer = new byte[8192];
int len = inputStream.read(buffer);
while (len != -1) {
messageDigest.update(buffer, 0, len);
len = inputStream.read(buffer);
}
return(new HexBinaryAdapter().marshal(messageDigest.digest()));
} catch (NoSuchAlgorithmException ex) {
throw new IOException(ex);
} finally {
IOUtils.closeQuietly(inputStream);
}
}
ChecksumHelper.java 文件源码
java
阅读 27
收藏 0
点赞 0
评论 0
项目:backblaze-b2-java-api
作者:
评论列表
文章目录