Class ExtractionUtil


  • @ThreadSafe
    public final class ExtractionUtil
    extends java.lang.Object
    Set of utilities to extract files from archives.
    Author:
    Jeremy Long
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void extractFiles​(java.io.File archive, java.io.File extractTo)
      Extracts the contents of an archive into the specified directory.
      static void extractFiles​(java.io.File archive, java.io.File extractTo, Engine engine)
      Extracts the contents of an archive into the specified directory.
      static void extractFiles​(java.io.InputStream archive, java.io.File extractTo)
      Extracts the contents of an archive into the specified directory.
      static void extractFilesUsingFilter​(java.io.File archive, java.io.File destination, java.io.FilenameFilter filter)
      Extracts the contents of an archive into the specified directory.
      static void extractGzip​(java.io.File file)
      Extracts the file contained in a gzip archive.
      static void extractZip​(java.io.File file)
      Extracts the file contained in a Zip archive.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • extractFiles

        public static void extractFiles​(java.io.File archive,
                                        java.io.File extractTo)
                                 throws ExtractionException
        Extracts the contents of an archive into the specified directory.
        Parameters:
        archive - an archive file such as a WAR or EAR
        extractTo - a directory to extract the contents to
        Throws:
        ExtractionException - thrown if an exception occurs while extracting the files
      • extractFiles

        public static void extractFiles​(java.io.File archive,
                                        java.io.File extractTo,
                                        Engine engine)
                                 throws ExtractionException
        Extracts the contents of an archive into the specified directory. The files are only extracted if they are supported by the analyzers loaded into the specified engine. If the engine is specified as null then all files are extracted.
        Parameters:
        archive - an archive file such as a WAR or EAR
        extractTo - a directory to extract the contents to
        engine - the scanning engine
        Throws:
        ExtractionException - thrown if there is an error extracting the files
      • extractFiles

        public static void extractFiles​(java.io.InputStream archive,
                                        java.io.File extractTo)
                                 throws ExtractionException
        Extracts the contents of an archive into the specified directory. The files are only extracted if they are supported by the analyzers loaded into the specified engine. If the engine is specified as null then all files are extracted.
        Parameters:
        archive - an archive file such as a WAR or EAR
        extractTo - a directory to extract the contents to
        Throws:
        ExtractionException - thrown if there is an error extracting the files
      • extractFilesUsingFilter

        public static void extractFilesUsingFilter​(java.io.File archive,
                                                   java.io.File destination,
                                                   java.io.FilenameFilter filter)
                                            throws ExtractionException
        Extracts the contents of an archive into the specified directory.
        Parameters:
        archive - an archive file such as a WAR or EAR
        destination - a directory to extract the contents to
        filter - determines which files get extracted
        Throws:
        ExtractionException - thrown if the archive is not found
      • extractGzip

        public static void extractGzip​(java.io.File file)
                                throws java.io.FileNotFoundException,
                                       java.io.IOException
        Extracts the file contained in a gzip archive. The extracted file is placed in the exact same path as the file specified.
        Parameters:
        file - the archive file
        Throws:
        java.io.FileNotFoundException - thrown if the file does not exist
        java.io.IOException - thrown if there is an error extracting the file.
      • extractZip

        public static void extractZip​(java.io.File file)
                               throws java.io.FileNotFoundException,
                                      java.io.IOException
        Extracts the file contained in a Zip archive. The extracted file is placed in the exact same path as the file specified.
        Parameters:
        file - the archive file
        Throws:
        java.io.FileNotFoundException - thrown if the file does not exist
        java.io.IOException - thrown if there is an error extracting the file.