public class ResourceUtil extends Object
Resource,
ResourceSource,
ClassLoader,
URLClassLoader,
URL,
InputStream| Constructor and Description |
|---|
ResourceUtil() |
| Modifier and Type | Method and Description |
|---|---|
static org.zeroturnaround.javarebel.Resource[] |
asArray(org.zeroturnaround.javarebel.Resource resource)
Creates a one-element array of
Resources. |
static InputStream |
asInputStream(URL url)
Creates a byte input stream from the given URL.
|
static InputStream |
asRawInputStream(URL url)
Creates a raw input stream from the given URL.
|
static org.zeroturnaround.javarebel.Resource |
asResource(URL url)
Creates a new
Resource object based on the given URL. |
static org.zeroturnaround.javarebel.Resource[] |
asResources(Enumeration<URL> urls)
Creates an array of
Resource objects
based on the given URL objects. |
static org.zeroturnaround.javarebel.Resource[] |
asResources(List<URL> urls)
Creates an array of
Resource objects
based on the given URL objects. |
static org.zeroturnaround.javarebel.Resource[] |
asResources(URL[] urls)
Creates an array of
Resource objects
based on the given URL objects. |
static URL[] |
concat(URL[] first,
URL[] second)
Concatenates two arrays of
URLs into one. |
static String |
concatClassPath(String first,
String second)
Concatenates two class paths.
|
static URL |
findResource(ClassLoader classloader,
String name)
Invokes the
findResource method of the given class loader. |
static URL[] |
findResources(ClassLoader classloader,
String name)
Invokes the
findResources method of the given class loader. |
static URL[] |
findResources(URLClassLoader classloader,
String name)
Invokes the
findResources method of the given URL class loader. |
static org.zeroturnaround.javarebel.Resource |
getClassResource(org.zeroturnaround.javarebel.ResourceSource source,
String className)
Finds a class resource using a resource finder.
|
static File |
getFileFromPathOrURL(String path)
Converts a file path or URL into a
File. |
static File |
getFileFromURL(String url)
Converts a URL into a
File. |
static File |
getFileFromURL(URL url)
Converts a URL into a
File. |
static URL |
makeURL(File file)
|
static URL |
makeURL(File jar,
String entry)
Converts a JAR entry into a
URL. |
static String |
toClassPath(URL[] urls)
Converts an array of
URLs into a class path. |
static Enumeration<URL> |
toEnumeration(URL[] urls)
Converts the array of
URLs to an Enumeration. |
static URL[] |
toURLs(Enumeration<URL> en)
Converts the
Enumeration to an array of URLs. |
public static URL findResource(ClassLoader classloader, String name)
findResource method of the given class loader.
In case of URLClassLoader the underlying public method is invoked directly.
Otherwise the protected method of the ClassLoader is invoked through the
reflection.
classloader - the class loader object.name - the name of the resource
(parameter passed to the underlying findResource method)URL for the resource, or null
if the resource could not be found.URLClassLoader.findResource(String)public static URL[] findResources(ClassLoader classloader, String name)
findResources method of the given class loader.
In case of URLClassLoader the underlying public method is invoked directly.
Otherwise the protected method of the ClassLoader is invoked through the
reflection.
The underlying Enumeration is converted to an array of URLs.
classloader - the class loader object.name - the resource name.
(parameter passed to the underlying findResources method)URLs for the resources, or null
if no resource could be found.URLClassLoader.findResources(String),
findResources(URLClassLoader, String),
findResource(ClassLoader, String),
toURLs(Enumeration)public static URL[] findResources(URLClassLoader classloader, String name)
findResources method of the given URL class loader.
The underlying public method is invoked directly and
the Enumeration is converted to an array of URLs.
classloader - the class loader object.name - the resource name.
(parameter passed to the underlying findResources method)URLs for the resources, or null
if no resource could be found.URLClassLoader.findResources(String),
findResources(ClassLoader, String),
findResource(ClassLoader, String),
toURLs(Enumeration)public static URL[] toURLs(Enumeration<URL> en)
Enumeration to an array of URLs.en - an Enumeration of URLs (not null).URLs.toEnumeration(URL[])public static Enumeration<URL> toEnumeration(URL[] urls)
URLs to an Enumeration.urls - an array of URLs (not null).Enumeration of URLstoURLs(Enumeration)public static URL[] concat(URL[] first, URL[] second)
URLs into one.first - first array of URLs (maybe null)second - second array of URLs (maybe null)URLs containing all elements (maybe null).public static String concatClassPath(String first, String second)
first - first class path.second - second class path.public static String toClassPath(URL[] urls)
URLs into a class path.
URL will be separated by File.pathSeparators.
urls - array of URLs (maybe null)public static org.zeroturnaround.javarebel.Resource getClassResource(org.zeroturnaround.javarebel.ResourceSource source,
String className)
This is used in BaseClassResourceSource
which is the base implementation of ClassResourceSource.
The class name is converted to a resource name
by replacing all dots with slashes
and adding .class to the end.
source - the resource finder.className - the name of the class.Resource that corresponds to the given class.ResourceSource,
ClassResourceSource,
BaseClassResourceSourcepublic static org.zeroturnaround.javarebel.Resource[] asArray(org.zeroturnaround.javarebel.Resource resource)
Resources.resource - the Resource element.null if the element was null.public static org.zeroturnaround.javarebel.Resource asResource(URL url)
Resource object based on the given URL.
If a file or vfsfile protocol is used
a FileResource will be created.
Otherwise a new URLResource instance will be returned.
url - the resource URL.Resource object based on the given URL.public static org.zeroturnaround.javarebel.Resource[] asResources(URL[] urls)
Resource objects
based on the given URL objects.url - the resource URL objects.Resource objects.public static org.zeroturnaround.javarebel.Resource[] asResources(Enumeration<URL> urls)
Resource objects
based on the given URL objects.url - the resource URL objects.Resource objects.public static org.zeroturnaround.javarebel.Resource[] asResources(List<URL> urls)
Resource objects
based on the given URL objects.url - the resource URL objects.Resource objects.public static InputStream asRawInputStream(URL url)
url - URL object.asInputStream(URL)public static InputStream asInputStream(URL url)
url - URL object.asRawInputStream(URL)public static URL makeURL(File file) throws MalformedURLException
file - File object.URL object.MalformedURLExceptionpublic static URL makeURL(File jar, String entry) throws MalformedURLException
URL.file - a JAR file.entry - a JAR entry name.URL object.MalformedURLExceptionpublic static File getFileFromPathOrURL(String path) throws MalformedURLException
File.path - file path or URL.File object.MalformedURLExceptionpublic static File getFileFromURL(String url) throws MalformedURLException
File.url - URL.File object.MalformedURLExceptionCopyright © 2015. All rights reserved.