Class ResourceUtil
- Author:
- Rein Raudjärv
- See Also:
-
ResourceResourceSourceClassLoaderURLClassLoaderURLInputStream
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.zeroturnaround.javarebel.Resource[]asArray(org.zeroturnaround.javarebel.Resource resource) Creates a one-element array ofResources.static InputStreamasInputStream(URL url) Creates a byte input stream from the given URL.static InputStreamasRawInputStream(URL url) Creates a raw input stream from the given URL.static org.zeroturnaround.javarebel.ResourceasResource(URL url) Creates a newResourceobject based on the givenURL.static org.zeroturnaround.javarebel.Resource[]asResources(URL[] urls) Creates an array ofResourceobjects based on the givenURLobjects.static org.zeroturnaround.javarebel.Resource[]asResources(Enumeration<URL> urls) Creates an array ofResourceobjects based on the givenURLobjects.static org.zeroturnaround.javarebel.Resource[]asResources(List<URL> urls) Creates an array ofResourceobjects based on the givenURLobjects.static URL[]Concatenates two arrays ofURLs into one.static StringconcatClassPath(String first, String second) Concatenates two class paths.static URLfindResource(ClassLoader classloader, String name) Invokes thefindResourcemethod of the given class loader.static URL[]findResources(ClassLoader classloader, String name) Invokes thefindResourcesmethod of the given class loader.static URL[]findResources(URLClassLoader classloader, String name) Invokes thefindResourcesmethod of the given URL class loader.static org.zeroturnaround.javarebel.ResourcegetClassResource(org.zeroturnaround.javarebel.ResourceSource source, String className) Finds a class resource using a resource finder.static FilegetFileFromPathOrURL(String path) Converts a file path or URL into aFile.static FilegetFileFromURL(String url) Converts a URL into aFile.static FilegetFileFromURL(URL url) Converts a URL into aFile.static URLstatic URLConverts a JAR entry into aURL.static StringtoClassPath(URL[] urls) Converts an array ofURLs into a class path.static Enumeration<URL>static Enumeration<URL>toEnumeration(URL[] urls) Converts the array ofURLs to anEnumeration.static URL[]toURLs(Enumeration<URL> en) Converts theEnumerationto an array ofURLs.
-
Constructor Details
-
ResourceUtil
public ResourceUtil()
-
-
Method Details
-
findResource
Invokes thefindResourcemethod of the given class loader.In case of
URLClassLoaderthe underlying public method is invoked directly. Otherwise the protected method of theClassLoaderis invoked through the reflection.- Parameters:
classloader- the class loader object.name- the name of the resource (parameter passed to the underlyingfindResourcemethod)- Returns:
- a
URLfor the resource, ornullif the resource could not be found. - See Also:
-
findResources
Invokes thefindResourcesmethod of the given class loader.In case of
URLClassLoaderthe underlying public method is invoked directly. Otherwise the protected method of theClassLoaderis invoked through the reflection.The underlying
Enumerationis converted to an array ofURLs.- Parameters:
classloader- the class loader object.name- the resource name. (parameter passed to the underlyingfindResourcesmethod)- Returns:
URLs for the resources, ornullif no resource could be found.- See Also:
-
findResources
Invokes thefindResourcesmethod of the given URL class loader.The underlying public method is invoked directly and the
Enumerationis converted to an array ofURLs.- Parameters:
classloader- the class loader object.name- the resource name. (parameter passed to the underlyingfindResourcesmethod)- Returns:
URLs for the resources, ornullif no resource could be found.- See Also:
-
toURLs
Converts theEnumerationto an array ofURLs.- Parameters:
en- anEnumerationofURLs (notnull).- Returns:
- an array of
URLs. - See Also:
-
toEnumeration
Converts the array ofURLs to anEnumeration.- Parameters:
urls- an array ofURLs (notnull).- Returns:
- an
EnumerationofURLs - See Also:
-
toEnumeration
-
concat
Concatenates two arrays ofURLs into one.- Parameters:
first- first array ofURLs (maybenull)second- second array ofURLs (maybenull)- Returns:
- array of
URLs containing all elements (maybenull).
-
concatClassPath
Concatenates two class paths.- Parameters:
first- first class path.second- second class path.- Returns:
- result containing both class path entries.
-
toClassPath
Converts an array ofURLs into a class path.URLwill be separated byFile.pathSeparators.- Parameters:
urls- array ofURLs (maybenull)- Returns:
- class path.
-
getClassResource
public static org.zeroturnaround.javarebel.Resource getClassResource(org.zeroturnaround.javarebel.ResourceSource source, String className) Finds a class resource using a resource finder.This is used in
BaseClassResourceSourcewhich is the base implementation ofClassResourceSource.The class name is converted to a resource name by replacing all dots with slashes and adding
.classto the end.- Parameters:
source- the resource finder.className- the name of the class.- Returns:
Resourcethat corresponds to the given class.- See Also:
-
ResourceSourceClassResourceSourceBaseClassResourceSource
-
asArray
public static org.zeroturnaround.javarebel.Resource[] asArray(org.zeroturnaround.javarebel.Resource resource) Creates a one-element array ofResources.- Parameters:
resource- theResourceelement.- Returns:
- a one-element array with the given element
or
nullif the element wasnull.
-
asResource
Creates a newResourceobject based on the givenURL.If a
fileorvfsfileprotocol is used aFileResourcewill be created. Otherwise a newURLResourceinstance will be returned.- Parameters:
url- the resourceURL.- Returns:
- new
Resourceobject based on the givenURL.
-
asResources
Creates an array ofResourceobjects based on the givenURLobjects.- Parameters:
urls- the resourceURLobjects.- Returns:
- new
Resourceobjects.
-
asResources
Creates an array ofResourceobjects based on the givenURLobjects.- Parameters:
urls- the resourceURLobjects.- Returns:
- new
Resourceobjects.
-
asResources
Creates an array ofResourceobjects based on the givenURLobjects.- Parameters:
urls- the resourceURLobjects.- Returns:
- new
Resourceobjects.
-
asRawInputStream
Creates a raw input stream from the given URL.- Parameters:
url-URLobject.- Returns:
- a raw input stream.
- See Also:
-
asInputStream
Creates a byte input stream from the given URL.- Parameters:
url-URLobject.- Returns:
- a byte input stream.
- See Also:
-
makeURL
- Parameters:
file-Fileobject.- Returns:
URLobject.- Throws:
MalformedURLException
-
makeURL
Converts a JAR entry into aURL.- Parameters:
jar- a JAR file.entry- a JAR entry name.- Returns:
URLobject.- Throws:
MalformedURLException
-
getFileFromPathOrURL
Converts a file path or URL into aFile.- Parameters:
path- file path or URL.- Returns:
Fileobject.- Throws:
MalformedURLException
-
getFileFromURL
Converts a URL into aFile.- Parameters:
url- URL.- Returns:
Fileobject.- Throws:
MalformedURLException
-
getFileFromURL
Converts a URL into aFile.- Parameters:
url- URL.- Returns:
Fileobject.
-