Class ResourceUtils

java.lang.Object
org.zeroturnaround.javarebel.support.ResourceUtils

public abstract class ResourceUtils extends Object
Utility methods for resolving resource locations to files in the file system.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    URL protocol for an entry from a JBoss jar file: "vfszip"
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Extract the JAR entry from the given URL
    static URL
    Extract the URL for the actual jar file from the given URL (which may point to a resource in a jar file or to a jar file itself).
    static File
    getFile(URI resourceUri)
     
    static File
    getFile(URL resourceUrl)
    Resolve the given resource URL to a java.io.File, i.e.
    static File
    getFile(URL resourceUrl, String description)
    Resolve the given resource URL to a java.io.File, i.e.
    static File
    getFile(URL resourceUrl, org.zeroturnaround.javarebel.RebelServletContext sc)
    Resolve the given resource URL to a java.io.File, i.e.
    static File[]
    getFiles(URL[] resourceUrls)
     
    static boolean
    Determine whether the given URL points to a resource in the file system.
    static boolean
    Determine whether the given URL points to a resource in a jar file, that is, has protocol "jar", "zip", "wsjar" or "code-source".
    static boolean
    Determine if the jar entry is in a nested jar
    static boolean
    Determines if the parameter is a URL with a protocol or not
    static boolean
     
    static URI
    toURI(String location)
    Create a URI instance for the given location String, replacing spaces with "%20" quotes first.
    static URI
    toURI(URL url)
    Create a URI instance for the given URL, replacing spaces with "%20" quotes first.

    Methods inherited from class java.lang.Object

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

    • URL_PROTOCOL_VFSZIP

      public static final String URL_PROTOCOL_VFSZIP
      URL protocol for an entry from a JBoss jar file: "vfszip"
      See Also:
  • Constructor Details

    • ResourceUtils

      public ResourceUtils()
  • Method Details

    • isUrl

      public static boolean isUrl(String s)
      Determines if the parameter is a URL with a protocol or not
      Parameters:
      s - a String to check if it's URL
      Returns:
      a true if the s was url
    • getFile

      public static File getFile(URL resourceUrl, org.zeroturnaround.javarebel.RebelServletContext sc)
      Resolve the given resource URL to a java.io.File, i.e. to a file in the file system.
      Parameters:
      resourceUrl - the resource URL to resolve
      sc - a backup RebelServletContext to make some checks
      Returns:
      a corresponding File object or null
    • getFile

      public static File getFile(URL resourceUrl)
      Resolve the given resource URL to a java.io.File, i.e. to a file in the file system.
      Parameters:
      resourceUrl - the resource URL to resolve
      Returns:
      a corresponding File object
    • getFile

      public static File getFile(URI resourceUri)
    • getFiles

      public static File[] getFiles(URL[] resourceUrls)
    • getFile

      public static File getFile(URL resourceUrl, String description)
      Resolve the given resource URL to a java.io.File, i.e. to a file in the file system.
      Parameters:
      resourceUrl - the resource URL to resolve
      description - a description of the original resource that the URL was created for (for example, a class path location)
      Returns:
      a corresponding File object
    • isFileURL

      public static boolean isFileURL(URL url)
      Determine whether the given URL points to a resource in the file system.
      Parameters:
      url - the URL to check. May be null.
      Returns:
      true if url references a file
    • isJarURL

      public static boolean isJarURL(URL url)
      Determine whether the given URL points to a resource in a jar file, that is, has protocol "jar", "zip", "wsjar" or "code-source".

      "zip" and "wsjar" are used by BEA WebLogic Server and IBM WebSphere, respectively, but can be treated like jar files. The same applies to "code-source" URLs on Oracle OC4J, provided that the path contains a jar separator.

      Parameters:
      url - the URL to check. May be null.
      Returns:
      whether the URL has been identified as a JAR URL
    • isVirtualJarURL

      public static boolean isVirtualJarURL(URL url)
    • isNestedJarEntry

      public static boolean isNestedJarEntry(String entry)
      Determine if the jar entry is in a nested jar
      Parameters:
      entry - Then name of the entry in the jar file
      Returns:
      if the entry is in a nested jar
    • extractJarFileURL

      public static URL extractJarFileURL(URL jarUrl)
      Extract the URL for the actual jar file from the given URL (which may point to a resource in a jar file or to a jar file itself).
      Parameters:
      jarUrl - the original URL
      Returns:
      the URL for the actual jar file
    • extractJarEntryPath

      public static String extractJarEntryPath(URL jarUrl)
      Extract the JAR entry from the given URL
      Parameters:
      jarUrl - the original URL
      Returns:
      the JAR entry
    • toURI

      public static URI toURI(URL url) throws URISyntaxException
      Create a URI instance for the given URL, replacing spaces with "%20" quotes first.

      Furthermore, this method works on JDK 1.4 as well, in contrast to the URL.toURI() method.

      Parameters:
      url - the URL to convert into a URI instance
      Returns:
      the URI instance
      Throws:
      URISyntaxException - if the URL wasn't a valid URI
      See Also:
    • toURI

      public static URI toURI(String location) throws URISyntaxException
      Create a URI instance for the given location String, replacing spaces with "%20" quotes first.
      Parameters:
      location - the location String to convert into a URI instance
      Returns:
      the URI instance
      Throws:
      URISyntaxException - if the location wasn't a valid URI