Class JarUtils

java.lang.Object
net.ssehub.easy.basics.io.JarUtils

public class JarUtils extends Object
Some helpful Jar methods. Could be partially be replaced by JDK 7 FileSystem, but currently this bundle is built for JDK5.
Author:
Holger Eichelberger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Returns whether the given uri is a Jar URI as returned, e.g., by a classloader.
    static boolean
    Returns whether the given url is a JAR URL as returned, e.g., by a classloader.
    static void
    unpackJar(URL url, File target)
    Unpacks a Jar file denoted by url to the given target folder.
    static void
    unpackJar(URL url, String resource, File target)
    Unpacks a Jar file denoted by url to the given target folder.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JarUtils

      public JarUtils()
  • Method Details

    • isJarURI

      public static boolean isJarURI(URI uri)
      Returns whether the given uri is a Jar URI as returned, e.g., by a classloader.
      Parameters:
      uri - the URI (ignored if null)
      Returns:
      true for a Jar URI, false else
    • isJarURL

      public static boolean isJarURL(URL url)
      Returns whether the given url is a JAR URL as returned, e.g., by a classloader.
      Parameters:
      url - the URL (ignored if null)
      Returns:
      true for a JAR URL, false else
    • unpackJar

      public static void unpackJar(URL url, File target) throws MalformedURLException, IOException
      Unpacks a Jar file denoted by url to the given target folder. target may not exist and is created then. Existing files are overwritten.
      Parameters:
      url - the Jar URL
      target - the target folder
      Throws:
      MalformedURLException - in case that the URL is ill formed or not a Jar URL
      IOException - in case of any I/O problems
    • unpackJar

      public static void unpackJar(URL url, String resource, File target) throws IOException
      Unpacks a Jar file denoted by url to the given target folder. target may not exist and is created then. Existing files are overwritten.
      Parameters:
      url - the Jar URL
      resource - a resource within the JAR to extract, may be a file or a folder in JAR format specification, i.e., without leading / but trailing /
      target - the target folder
      Throws:
      MalformedURLException - in case that the URL is ill formed or not a Jar URL
      IOException - in case of any I/O problems