use of org.compiere.util.DigestOfFile in project adempiere by adempiere.
the class MD5Bean method getFileMD5.
/**
* Business method
* @param FileName
* @return hash base64 encoded
*/
public String getFileMD5(String FileName) {
String hash = null;
String absoluteFilename = null;
String filepartOnly = null;
try {
//Thread.currentThread().getContextClassLoader().getResource("");
if (FileName.startsWith("http://")) {
//extract absolute path by requesting jboss/tomcat
String[] filePathParts = FileName.split("/");
filepartOnly = filePathParts[filePathParts.length - 1];
URL currentFile = Thread.currentThread().getContextClassLoader().getResource(filepartOnly);
System.out.println(filepartOnly);
absoluteFilename = currentFile.getFile();
log.info("decoded absolute path name for " + filepartOnly + " is " + absoluteFilename);
} else {
absoluteFilename = FileName;
}
if (absoluteFilename != null) {
DigestOfFile md5DigestAgent = new DigestOfFile("MD5");
hash = md5DigestAgent.digestAsBase64(new java.io.File(absoluteFilename));
}
} catch (Exception e) {
log.severe(e.getMessage());
return null;
}
return hash;
}
Aggregations