@SuppressWarnings("empty-statement")
/**
 * This method will generate a SHA-256 Scanner_Checksum of a given file
 *
 * @param hash - possible values: SHA-1, SHA-256, SHA-512 and MD5
 * @param filename - the target filename, we also handle locked files
 * @return - the resulting Scanner_Checksum or empty if not possible to compute
 */
 public static String generateFileChecksum(String hash, File filename){

       String checksum;
       FileInputStream fis = null;

        try {  // SHA-256
            MessageDigest md = MessageDigest.getInstance(hash);
//              try {
                fis = new FileInputStream(filename);
//            } catch (Exception e) {
//                //log("error", "No Scanner_Checksum performed for " + filename);
//
//                return "";
//            }
            byte[] dataBytes = new byte[1024];
            int nread = 0;
            while ((nread = fis.read(dataBytes)) != -1) {
                md.update(dataBytes, 0, nread);
            };
            //fis.close();


            byte[] mdbytes = md.digest();
            //convert the byte to hex format method 1
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < mdbytes.length; i++) {
                sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
            }
            checksum = sb.toString();
        } catch (IOException ex) {
           if(debug == true)
            Logger.getLogger(checksum.class.getName()).log(Level.SEVERE, null, ex);
                //log("error", "No Scanner_Checksum performed for " + filename);
                return "";
        } catch (NoSuchAlgorithmException ex) {
           if(debug == true)
            Logger.getLogger(checksum.class.getName()).log(Level.SEVERE, null, ex);
                //log("error", "No Scanner_Checksum performed for " + filename);
                return "";
        } finally {
            try {
                if(fis!=null)
                    fis.close();
            } catch (IOException ex) {
             if(debug == true)
               Logger.getLogger(checksum.class.getName()).log(Level.SEVERE, null, ex);
                return "";
            }
        }


   return checksum;
   }