FileUtil { public static String getFileChecksum( final String fileAbsPath, ChecksumMethod checksumMethod ) { if ( ( StringUtils.isBlank( fileAbsPath ) ) || ( checksumMethod == null ) ) { return null; } File file = new File( fileAbsPath ); if ( ( !file.exists() ) || ( !file.isFile() ) ) { return null; } FileInputStream fis = null; BufferedInputStream bis = null; try { fis = new FileInputStream( file ); bis = new BufferedInputStream( fis ); if ( checksumMethod == ChecksumMethod.SHA1 ) { return DigestUtils.sha1Hex( bis ); } else if ( checksumMethod == ChecksumMethod.MD5 ) { return DigestUtils.md5Hex( bis ); } else if ( checksumMethod == ChecksumMethod.SHA256 ) { return DigestUtils.sha256Hex( bis ); } } catch ( FileNotFoundException e ) { logger.error( "Error while computing checksum for the file - {} using algorithm - {}.", fileAbsPath, checksumMethod.toString(), e ); } catch ( IOException e ) { logger.error( "Error while computing checksum for the file - {} using algorithm - {}.", fileAbsPath, checksumMethod.toString(), e ); } finally { try { if ( bis != null ) { bis.close(); } if ( fis != null ) { fis.close(); } } catch ( IOException e ) { } } return null; } private  FileUtil(); static boolean isFileExists( final String dirAbsPath, final String fileName ); static boolean isFileExists( final String fileAbsPath ); static boolean isDirExists( final String dirAbsPath ); static File[] findFiles( final String dirAbsPath, final String ext ); static boolean setFilesExecutable( final String dirAbsPath, final String ext ); static boolean extractArchive( final String archiveFileAbsPath, final String destDirAbsPath ); static boolean extractArchive( final File archiveFile, final File destDir ); static File[] findFiles( final String dirAbsPath, final String[] extensions, boolean recursive ); static File[] findFiles( final File dirAbsPath, final String[] extensions, boolean recursive ); static File[] findFiles( final String dirAbsPath, final String fileNamePattern, boolean recursive ); static String getFileChecksum( final String fileAbsPath, ChecksumMethod checksumMethod ); static boolean deleteDirectory( final String directory ); static boolean deleteDirectory( final File directory ); static String getTemporaryFolderPath(); static boolean deleteFile( final String filePath ); static boolean createDirectory( final String dirPath ); static String getFileBaseName( final String fileName ); static boolean unzipFile( final String zipFileAbsPath, final String outputDirAbsPath ); static boolean createOrUpdateFile( final String filePath, final String fileContent ); static boolean createOrUpdateFile( final String filePath, final String fileContent,
                                              final boolean createBackup ); static boolean createNewFile( final String fileAbsPath ); static String readFileToString( final String fileName ); static String findLatestFileByLastModified( final String directory, final String fileNamePattern,
                                                       final boolean recursive );  }
@Test @Ignore public void testGetFileChecksum() { String checksum = FileUtil.getFileChecksum( "/Users/sivakrishna/work/bundle-EVORACK-0.0.2-hms.tar", ChecksumMethod.SHA1 ); assertTrue( checksum.equalsIgnoreCase( "1be59e6a535497fc39eee2119bc158341d9abfd0" ) ); }