dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzer.java
/**
     * Extracts the contents of an archive into the specified directory.
     *
     * @param archive an archive file such as a WAR or EAR
     * @param destination a directory to extract the contents to
     * @param engine the scanning engine
     * @throws AnalysisException thrown if the archive is not found
     */
Extracts the contents of an archive into the specified directory.
@param archive an archive file such as a WAR or EAR
@param destination a directory to extract the contents to
@param engine the scanning engine
@throws AnalysisException thrown if the archive is not found
Extracts the contents of an archive into the specified directory . @param archive an archive file such as a WAR or EAR @param destination a directory to extract the contents to @param engine the scanning engine @throws AnalysisException thrown if the archive is not found
private void extractFiles(File archive, File destination, Engine engine) throws AnalysisException {
        if (archive != null && destination != null) {
            String archiveExt = FileUtils.getFileExtension(archive.getName());
            if (archiveExt == null) {
                return;
            }
            archiveExt = archiveExt.toLowerCase();
            final FileInputStream fis;
            try {
                fis = new FileInputStream(archive);
            } catch (FileNotFoundException ex) {
                LOGGER.debug("", ex);
                throw new AnalysisException("Archive file was not found.", ex);
            }
            BufferedInputStream in = null;
            ZipArchiveInputStream zin = null;
            TarArchiveInputStream tin = null;
            GzipCompressorInputStream gin = null;
            BZip2CompressorInputStream bzin = null;
            try {
                if (KNOWN_ZIP_EXT.contains(archiveExt)) {
                    in = new BufferedInputStream(fis);
                    ensureReadableJar(archiveExt, in);
                    zin = new ZipArchiveInputStream(in);
                    extractArchive(zin, destination, engine);
                } else if ("tar".equals(archiveExt)) {
                    in = new BufferedInputStream(fis);
                    tin = new TarArchiveInputStream(in);
                    extractArchive(tin, destination, engine);
                } else if ("gz".equals(archiveExt) || "tgz".equals(archiveExt)) {
                    final String uncompressedName = GzipUtils.getUncompressedFilename(archive.getName());
                    final File f = new File(destination, uncompressedName);
                    if (engine.accept(f)) {
                        in = new BufferedInputStream(fis);
                        gin = new GzipCompressorInputStream(in);
                        decompressFile(gin, f);
                    }
                } else if ("bz2".equals(archiveExt) || "tbz2".equals(archiveExt)) {
                    final String uncompressedName = BZip2Utils.getUncompressedFilename(archive.getName());
                    final File f = new File(destination, uncompressedName);
                    if (engine.accept(f)) {
                        in = new BufferedInputStream(fis);
                        bzin = new BZip2CompressorInputStream(in);
                        decompressFile(bzin, f);
                    }
                }
            } catch (ArchiveExtractionException ex) {
                LOGGER.warn("Exception extracting archive '{}'.", archive.getName());
                LOGGER.debug("", ex);
            } catch (IOException ex) {
                LOGGER.warn("Exception reading archive '{}'.", archive.getName());
                LOGGER.debug("", ex);
            } finally {
                FileUtils.close(fis);
                FileUtils.close(in);
                FileUtils.close(zin);
                FileUtils.close(tin);
                FileUtils.close(gin);
                FileUtils.close(bzin);
            }
        }
    }
private void extractFiles ( File archive , File destination , Engine engine ) throws AnalysisException { if ( archive != null && destination != null ) { String archiveExt = FileUtils . getFileExtension ( archive . getName ( ) ) ; if ( archiveExt == null ) { return ; } archiveExt = archiveExt . toLowerCase ( ) ; final FileInputStream fis ; try { fis = new FileInputStream ( archive ) ; } catch ( FileNotFoundException ex ) { LOGGER . debug ( "" , ex ) ; throw new AnalysisException ( "Archive file was not found." , ex ) ; } BufferedInputStream in = null ; ZipArchiveInputStream zin = null ; TarArchiveInputStream tin = null ; GzipCompressorInputStream gin = null ; BZip2CompressorInputStream bzin = null ; try { if ( KNOWN_ZIP_EXT . contains ( archiveExt ) ) { in = new BufferedInputStream ( fis ) ; ensureReadableJar ( archiveExt , in ) ; zin = new ZipArchiveInputStream ( in ) ; extractArchive ( zin , destination , engine ) ; } else if ( "tar" . equals ( archiveExt ) ) { in = new BufferedInputStream ( fis ) ; tin = new TarArchiveInputStream ( in ) ; extractArchive ( tin , destination , engine ) ; } else if ( "gz" . equals ( archiveExt ) || "tgz" . equals ( archiveExt ) ) { final String uncompressedName = GzipUtils . getUncompressedFilename ( archive . getName ( ) ) ; final File f = new File ( destination , uncompressedName ) ; if ( engine . accept ( f ) ) { in = new BufferedInputStream ( fis ) ; gin = new GzipCompressorInputStream ( in ) ; decompressFile ( gin , f ) ; } } else if ( "bz2" . equals ( archiveExt ) || "tbz2" . equals ( archiveExt ) ) { final String uncompressedName = BZip2Utils . getUncompressedFilename ( archive . getName ( ) ) ; final File f = new File ( destination , uncompressedName ) ; if ( engine . accept ( f ) ) { in = new BufferedInputStream ( fis ) ; bzin = new BZip2CompressorInputStream ( in ) ; decompressFile ( bzin , f ) ; } } } catch ( ArchiveExtractionException ex ) { LOGGER . warn ( "Exception extracting archive '{}'." , archive . getName ( ) ) ; LOGGER . debug ( "" , ex ) ; } catch ( IOException ex ) { LOGGER . warn ( "Exception reading archive '{}'." , archive . getName ( ) ) ; LOGGER . debug ( "" , ex ) ; } finally { FileUtils . close ( fis ) ; FileUtils . close ( in ) ; FileUtils . close ( zin ) ; FileUtils . close ( tin ) ; FileUtils . close ( gin ) ; FileUtils . close ( bzin ) ; } } }
Extracts the contents of an archive into the specified directory.
Extracts the contents of an archive into the specified directory .
//overly verbose and not needed... but keeping it anyway due to //having issue with file handles being left open