try {
messageDigest = MessageDigest.getInstance(HASH_ALGORITHM);
} catch (NoSuchAlgorithmException e) {
throw new IOException(e);
}
DigestInputStream din = new DigestInputStream(in, messageDigest);
long length = file.length();
try {
while (true) {
int len = din.read(buffer, 0, buffer.length);
if (len < 0) {
break;
}
}
} finally {
din.close();
}
ByteArrayOutputStream idStream = new ByteArrayOutputStream();
idStream.write(TYPE_HASH);
IOUtils.writeVarInt(idStream, 0);
IOUtils.writeVarLong(idStream, length);