FileUtil { public static boolean unzipFile( final String zipFileAbsPath, final String outputDirAbsPath ) { if ( StringUtils.isBlank( zipFileAbsPath ) || StringUtils.isBlank( outputDirAbsPath ) || ( !FileUtil.isFileExists( zipFileAbsPath ) ) ) { logger.debug( "" ); return false; } ZipFile zipFile = null; try { zipFile = new ZipFile( zipFileAbsPath ); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while ( entries.hasMoreElements() ) { ZipEntry entry = entries.nextElement(); File entryDestination = new File( outputDirAbsPath, entry.getName() ); if ( entry.isDirectory() ) { entryDestination.mkdirs(); } else { entryDestination.getParentFile().mkdirs(); InputStream in = zipFile.getInputStream( entry ); OutputStream out = new FileOutputStream( entryDestination ); IOUtils.copy( in, out ); IOUtils.closeQuietly( in ); IOUtils.closeQuietly( out ); } } return true; } catch ( IOException e ) { logger.error( "Error while unzipping zip file: {}", zipFileAbsPath, e ); } finally { try { if ( zipFile != null ) { zipFile.close(); } } catch ( IOException e ) { logger.warn( "Error while closing zip file.", e ); } } return false; } 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 testUnzipFile() { final String zipFile = "/Users/sivakrishna/work/hms-aggregator.war"; final String outputDir = "/tmp"; assertTrue( FileUtil.unzipFile( zipFile, outputDir ) ); }