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 StringURL_PROTOCOL_VFSZIPURL protocol for an entry from a JBoss jar file: "vfszip"
-
Constructor Summary
Constructors Constructor Description ResourceUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringextractJarEntryPath(URL jarUrl)Extract the JAR entry from the given URLstatic URLextractJarFileURL(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).static FilegetFile(URI resourceUri)static FilegetFile(URL resourceUrl)Resolve the given resource URL to ajava.io.File, i.e.static FilegetFile(URL resourceUrl, String description)Resolve the given resource URL to ajava.io.File, i.e.static FilegetFile(URL resourceUrl, org.zeroturnaround.javarebel.RebelServletContext sc)Resolve the given resource URL to ajava.io.File, i.e.static File[]getFiles(URL[] resourceUrls)static booleanisFileURL(URL url)Determine whether the given URL points to a resource in the file system.static booleanisJarURL(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".static booleanisNestedJarEntry(String entry)Determine if the jar entry is in a nested jarstatic booleanisUrl(String s)Determines if the parameter is a URL with a protocol or notstatic booleanisVirtualJarURL(URL url)static URItoURI(String location)Create a URI instance for the given location String, replacing spaces with "%20" quotes first.static URItoURI(URL url)Create a URI instance for the given URL, replacing spaces with "%20" quotes first.
-
-
-
Field Detail
-
URL_PROTOCOL_VFSZIP
public static final String URL_PROTOCOL_VFSZIP
URL protocol for an entry from a JBoss jar file: "vfszip"- See Also:
- Constant Field Values
-
-
Method Detail
-
isUrl
public static boolean isUrl(String s)
Determines if the parameter is a URL with a protocol or not
-
getFile
public static File getFile(URL resourceUrl, org.zeroturnaround.javarebel.RebelServletContext sc)
Resolve the given resource URL to ajava.io.File, i.e. to a file in the file system.- Parameters:
resourceUrl- the resource URL to resolve- Returns:
- a corresponding File object or null
-
getFile
public static File getFile(URL resourceUrl)
Resolve the given resource URL to ajava.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(URL resourceUrl, String description)
Resolve the given resource URL to ajava.io.File, i.e. to a file in the file system.- Parameters:
resourceUrl- the resource URL to resolvedescription- 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.
-
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:
URL.toURI()
-
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
-
-