private boolean unTar ( String fileName , String innerDir , String archiveFile ) { boolean success = true ; TarUnArchiver unArchiver = new TarUnArchiver ( ) ; try { File destDir = new File ( innerDir ) ; if ( ! destDir . exists ( ) ) { destDir . mkdirs ( ) ; } if ( fileName . endsWith ( TAR_GZ_SUFFIX ) || fileName . endsWith ( TGZ_SUFFIX ) ) { unArchiver = new TarGZipUnArchiver ( ) ; } else if ( fileName . endsWith ( TAR_BZ2_SUFFIX ) ) { unArchiver = new TarBZip2UnArchiver ( ) ; } else if ( fileName . endsWith ( XZ_SUFFIX ) ) { String destFileUrl = destDir . getCanonicalPath ( ) + Constants . BACK_SLASH + XZ_UN_ARCHIVER_FILE_NAME ; success = unXz ( new File ( archiveFile ) , destFileUrl ) ; archiveFile = destFileUrl ; } if ( success ) { unArchiver . enableLogging ( new ConsoleLogger ( ConsoleLogger . LEVEL_DISABLED , UN_ARCHIVER_LOGGER ) ) ; unArchiver . setSourceFile ( new File ( archiveFile ) ) ; unArchiver . setDestDirectory ( destDir ) ; unArchiver . extract ( ) ; } } catch ( Exception e ) { success = false ; logger . warn ( "Error extracting file {}: {}" , fileName , e . getMessage ( ) ) ; } return success ; }
Open and extract data from Tar pattern files