I'm programming a web service for uploading long files. The client sends the chunks whenever it wants. I need to calculate the hash of this file while theese chunks are received.
I've seen that you can do somenthing like this:
byte[] buf = new byte[8192];
MessageDigest sha = MessageDigest.getInstance("SHA1");
FileInputStream inp = new FileInputStream(new File("D:\\season4_mlp.rar"));
int n;
while((n = inp.read(buf)) > 0)
sha.update(buf, 0, n);
byte hash[] = sha.digest();
The problem is that I need to do this with different chunks of the same file and I don't know when they are going to come. I would need to keep the state of this hash calculation.