I have created a class to generate checksum for the files using apache file utils and bouncy castle to generate checksum. I have read the given file using apache's - IOUtils and I have used bouncy castle's - bcprov to generate checksum.
The code which I used as below :
byte[] digest = null;
String result = "";
SHA1.Digest sha1 = new SHA1.Digest();
sha1.update(IOUtils.toByteArray(new FileInputStream(file)));
digest = sha1.digest();
for (int i = 0; i < digest.length; i++)
{
result += Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1);
}
When I try to read a large size of file (i.e about 80MB file) I get out of memory space error as shown below
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.apache.commons.io.output.ByteArrayOutputStream.toByteArray(ByteAr rayOutputStream.java:322)
at org.apache.commons.io.IOUtils.toByteArray(IOUtils.java:463)
at com.test.hashgenerator.HashGenerator.getSHA1CheckSum(HashGe nerator.java:230)
at com.test.hashgenerator.HashGenerator.main(HashGenerator.jav a:319)
Is I need to enhance my code? Any help would be appreciated.