private byte[] cache(URL orig, File cachefile, File hashFile) throws IOException {
byte[] checksum = null;
cachefile.getParentFile().mkdirs();
cachefile.createNewFile();
FileOutputStream out = new FileOutputStream(cachefile);
MD5InputStream in = null;
try {
in = new MD5InputStream(orig.openStream());
try {
// Write the resource
IOUtil.copyStream(in, out);
} finally {
out.close();
}
FileOutputStream hashOut = new FileOutputStream(hashFile);
checksum = in.getHash();
try {
// Write the checksum
hashOut.write(checksum);
} finally {
hashOut.close();
}
} finally {
if (in != null) {
in.close();
}
}
return checksum;
}