Bookmark Topic Watch Topic
  • New Topic

Fastest way of calculating MD5  RSS feed

 
adi arrab
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Report post to moderator
I want to calculate MD5 values for a large Files I am using the following Code

public String Checker(File fi) throws NoSuchAlgorithmException,
FileNotFoundException {
MessageDigest md = MessageDigest.getInstance("MD5");
StopWatch stopWatch = new StopWatch();
InputStream is = new FileInputStream(fi);
byte[] buffer = new byte[4000];
int read = 0;
try {
stopWatch.start();
while ((read = is.read(buffer)) > 0) {
md.update(buffer, 0, read);
}
byte[] md5sum = md.digest();
BigInteger bigInt = new BigInteger(1, md5sum);
String output = bigInt.toString(16);
System.out.println("MD5 : " + output);
stopWatch.stop();
long s = stopWatch.getTime();
System.out.println("MD5 Time taken: " + s);
return output;
} catch (IOException e) {
throw new RuntimeException("Unable to process file for MD5", e);
} finally {
try {
is.close();
} catch (IOException e) {
throw new RuntimeException(
"Unable to close input stream for MD5 calculation", e);
}
}

}

For Million record file it takes 55 seconds


How can i increase the performance(ie decrease the processing time)

Any Suggestions or Code would help

Thanks take care
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't post the same question more than once.
Carefully Choose One Forum
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!