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