public class ResourceUtils
extends java.lang.Object
Constructor and Description |
---|
ResourceUtils(BrooklynClassLoadingContext loader,
java.lang.Object contextObject,
java.lang.String contextMessage) |
ResourceUtils(java.lang.ClassLoader loader,
java.lang.Object contextObject,
java.lang.String contextMessage) |
ResourceUtils(java.lang.Object contextObject) |
ResourceUtils(java.lang.Object contextObject,
java.lang.String contextMessage) |
Modifier and Type | Method and Description |
---|---|
static void |
addClassLoaderProvider(<any> provider)
used to register custom mechanisms for getting classloaders given an object
|
java.lang.String |
checkUrlExists(java.lang.String url) |
java.lang.String |
checkUrlExists(java.lang.String url,
java.lang.String message)
Throws if the given URL cannot be read.
|
static ResourceUtils |
create()
Creates a
ResourceUtils object with itself as the context. |
static ResourceUtils |
create(BrooklynClassLoadingContext loader,
java.lang.Object contextObject,
java.lang.String contextMessage)
Creates a
ResourceUtils object with a specific class loader and context. |
static ResourceUtils |
create(java.lang.ClassLoader loader,
java.lang.Object contextObject,
java.lang.String contextMessage)
Creates a
ResourceUtils object with a specific class loader and context. |
static ResourceUtils |
create(java.lang.Object contextObject)
Creates a
ResourceUtils object with the given context. |
static ResourceUtils |
create(java.lang.Object contextObject,
java.lang.String contextMessage)
Creates a
ResourceUtils object with the given context. |
boolean |
doesUrlExist(java.lang.String url) |
<any> |
firstAvailableUrl(java.lang.String... urls)
returns the first available URL
|
java.lang.String |
getClassLoaderDir()
returns the base directory or JAR from which the context is class-loaded, if possible;
throws exception if not found
|
java.lang.String |
getClassLoaderDir(java.lang.String resourceInThatDir) |
static java.net.URL |
getContainerUrl(java.net.URL url,
java.lang.String resourceInThatDir) |
java.lang.String |
getResourceAsString(java.lang.String url)
takes
getResourceFromUrl(String) and reads fully, into a string |
java.io.InputStream |
getResourceFromUrl(java.lang.String url)
Takes a string which is treated as a URL (with some extended "schemes" also expected),
or as a path to something either on the classpath (absolute only) or the local filesystem (relative or absolute, depending on leading slash)
|
java.io.InputStream |
getResourceFromUrl(java.lang.String url,
Credentials credentials) |
java.lang.Iterable<java.net.URL> |
getResources(java.lang.String name) |
static java.net.URL |
tidy(java.net.URL url) |
static java.lang.String |
tidyFileUrl(java.lang.String url) |
public ResourceUtils(java.lang.ClassLoader loader, java.lang.Object contextObject, java.lang.String contextMessage)
public ResourceUtils(BrooklynClassLoadingContext loader, java.lang.Object contextObject, java.lang.String contextMessage)
public ResourceUtils(java.lang.Object contextObject, java.lang.String contextMessage)
public ResourceUtils(java.lang.Object contextObject)
public static final ResourceUtils create(java.lang.ClassLoader loader, java.lang.Object contextObject, java.lang.String contextMessage)
ResourceUtils
object with a specific class loader and context.
Use the provided ClassLoader
object for class loading with the
contextObject
for context and the contextMessage
string for
error messages.
create(Object, String)
,
create(Object)
public static final ResourceUtils create(BrooklynClassLoadingContext loader, java.lang.Object contextObject, java.lang.String contextMessage)
ResourceUtils
object with a specific class loader and context.
Use the provided BrooklynClassLoadingContext
object for class loading with the
contextObject
for context and the contextMessage
string for
error messages.
create(Object, String)
,
create(Object)
public static final ResourceUtils create(java.lang.Object contextObject, java.lang.String contextMessage)
ResourceUtils
object with the given context.
Uses the ClassLoader
of the given contextObject
for class
loading and the contextMessage
string for error messages.
public static final ResourceUtils create(java.lang.Object contextObject)
ResourceUtils
object with the given context.
Uses the ClassLoader
of the given contextObject
for class
loading and its Object.toString()
(preceded by the word 'for') as
the string used in error messages.
public static final ResourceUtils create()
ResourceUtils
object with itself as the context.create(Object)
public static void addClassLoaderProvider(<any> provider)
public java.lang.Iterable<java.net.URL> getResources(java.lang.String name)
BrooklynClassLoadingContext
with the given name.public java.io.InputStream getResourceFromUrl(java.lang.String url, @Nullable Credentials credentials)
public java.io.InputStream getResourceFromUrl(java.lang.String url)
URLs can be of the form classpath://com/acme/Foo.properties as well as file:///home/... and http://acme.com/....
Throws exception if not found, using the context parameter passed into the constructor.
TODO may want OSGi, or typed object; should consider pax url
public static java.net.URL tidy(java.net.URL url)
public static java.lang.String tidyFileUrl(java.lang.String url)
public java.lang.String getResourceAsString(java.lang.String url)
getResourceFromUrl(String)
and reads fully, into a stringpublic java.lang.String checkUrlExists(java.lang.String url)
checkUrlExists(String, String)
public java.lang.String checkUrlExists(java.lang.String url, java.lang.String message)
url
- The URL to testmessage
- An optional message to use for the exception thrown.getResourceFromUrl(String)
public boolean doesUrlExist(java.lang.String url)
getResourceFromUrl(String)
public <any> firstAvailableUrl(java.lang.String... urls)
public java.lang.String getClassLoaderDir()
public java.lang.String getClassLoaderDir(java.lang.String resourceInThatDir)
public static java.net.URL getContainerUrl(java.net.URL url, java.lang.String resourceInThatDir)