public String extractFileFromArchive ( File downloadedCompressedFile , String extractedToFilePath , BinaryType possibleFilenames ) throws IOException , IllegalArgumentException , MojoFailureException { DownloadableFileType fileType = DownloadableFileType . valueOf ( FilenameUtils . getExtension ( downloadedCompressedFile . getName ( ) ) . toUpperCase ( ) ) ; LOG . debug ( "Determined archive type: " + fileType ) ; LOG . debug ( "Overwrite files that exist: " + overwriteFilesThatExist ) ; switch ( fileType ) { case GZ : case BZ2 : CompressedFile compressedFile = new CompressedFile ( downloadedCompressedFile ) ; if ( null != compressedFile . getArchiveType ( ) && compressedFile . getArchiveType ( ) . equals ( TAR ) ) { return untarFile ( compressedFile . getInputStream ( ) , extractedToFilePath , possibleFilenames ) ; } else { return copyFileToDisk ( compressedFile . getInputStream ( ) , extractedToFilePath , compressedFile . getDecompressedFilename ( ) ) ; } case ZIP : return unzipFile ( downloadedCompressedFile , extractedToFilePath , possibleFilenames ) ; case EXE : if ( possibleFilenames . getBinaryFilenames ( ) . contains ( downloadedCompressedFile . getName ( ) ) ) { return copyFileToDisk ( new FileInputStream ( downloadedCompressedFile ) , extractedToFilePath , downloadedCompressedFile . getName ( ) ) ; } default : throw new IllegalArgumentException ( "." + fileType + " is an unsupported archive type" ) ; } }
Extract binary from a downloaded archive file