MessageDigest sha = MessageDigest.getInstance("SHA-512");
DigestOutputStream dout = new DigestOutputStream(out, sha);
byte[] data = new byte[128];
while (true) {
int bytesRead = in.read(data);
if (bytesRead < 0) break;
dout.write(data, 0, bytesRead);
}
dout.flush();
byte[] result = dout.getMessageDigest().digest();
for (int i = 0; i < result.length; i++) {
System.out.print(result[i] + " ");
}
System.out.println();