Class ExpandJar


  • public class ExpandJar
    extends Object
    Expand out a jar. Adapted from Tomcat's org.apache.catalina.startup.ExpendWar classes
    Author:
    Jeanfrancois Arcand
    • Constructor Summary

      Constructors 
      Constructor Description
      ExpandJar()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean copy​(File src, File dest)
      Copy the specified file or directory to the destination.
      static boolean delete​(File dir)
      Delete the specified directory, including all of its contents and subdirectories recursively.
      static boolean deleteDir​(File dir)
      Delete the specified directory, including all of its contents and subdirectories recursively.
      protected static void expand​(InputStream input, File docBase, String name)
      Expand the specified input stream into the specified directory, creating a file named from the specified relative path.
      static String expand​(URL jar)
      Expand the jar file found at the specified URL into an unpacked directory structure, and return the absolute pathname to the expanded directory.
      static String expand​(URL jar, String workFolder)
      Expand the jar file found at the specified URL into an unpacked directory structure, and return the absolute pathname to the expanded directory.
      static String expand​(URL jar, String pathname, String dirname)
      Expand the jar file found at the specified URL into an unpacked directory structure, and return the absolute pathname to the expanded directory.
    • Constructor Detail

      • ExpandJar

        public ExpandJar()
    • Method Detail

      • expand

        public static String expand​(URL jar)
                             throws IOException
        Expand the jar file found at the specified URL into an unpacked directory structure, and return the absolute pathname to the expanded directory.
        Parameters:
        jar - URL of the web application archive to be expanded (must start with "jar:")
        Returns:
        Absolute path as in File.getAbsolutePath() of location where to find expanded jar.
        Throws:
        IllegalArgumentException - if this is not a "jar:" URL
        IOException - if an input/output error was encountered during expansion
      • expand

        public static String expand​(URL jar,
                                    String workFolder)
                             throws IOException
        Expand the jar file found at the specified URL into an unpacked directory structure, and return the absolute pathname to the expanded directory.
        Parameters:
        jar - URL of the web application archive to be expanded (must start with "jar:")
        workFolder - the folder where the file will be expanded
        Returns:
        Absolute path as in File.getAbsolutePath() of location where to find expanded jar.
        Throws:
        IllegalArgumentException - if this is not a "jar:" URL
        IOException - if an input/output error was encountered during expansion
      • expand

        public static String expand​(URL jar,
                                    String pathname,
                                    String dirname)
                             throws IOException
        Expand the jar file found at the specified URL into an unpacked directory structure, and return the absolute pathname to the expanded directory.
        Parameters:
        jar - URL of the web application archive to be expanded (must start with "jar:")
        pathname - Context path name for web application
        Returns:
        Absolute path as in File.getAbsolutePath() of location where to find expanded jar.
        Throws:
        IllegalArgumentException - if this is not a "jar:" URL
        IOException - if an input/output error was encountered during expansion
      • copy

        public static boolean copy​(File src,
                                   File dest)
        Copy the specified file or directory to the destination.
        Parameters:
        src - File object representing the source
        dest - File object representing the destination
      • delete

        public static boolean delete​(File dir)
        Delete the specified directory, including all of its contents and subdirectories recursively.
        Parameters:
        dir - File object representing the directory to be deleted
      • deleteDir

        public static boolean deleteDir​(File dir)
        Delete the specified directory, including all of its contents and subdirectories recursively.
        Parameters:
        dir - File object representing the directory to be deleted
      • expand

        protected static void expand​(InputStream input,
                                     File docBase,
                                     String name)
                              throws IOException
        Expand the specified input stream into the specified directory, creating a file named from the specified relative path.
        Parameters:
        input - InputStream to be copied
        docBase - Document base directory into which we are expanding
        name - Relative pathname of the file to be created
        Throws:
        IOException - if an input/output error occurs