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(com.google.common.base.Function<java.lang.Object,BrooklynClassLoadingContext> provider)
used to register custom mechanisms for getting classloaders given an object
|
static java.lang.Thread |
addShutdownHook(java.lang.Runnable task)
Deprecated.
since 0.7.0; use method
Threads.addShutdownHook(Runnable) |
java.lang.String |
checkUrlExists(java.lang.String url)
allows failing-fast if URL cannot be read
|
java.lang.String |
checkUrlExists(java.lang.String url,
java.lang.String message) |
static void |
copy(java.io.InputStream input,
java.io.OutputStream output)
Deprecated.
since 0.7.0 use
Streams.copy(InputStream, OutputStream) |
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)
tests whether the url exists, returning true or false
|
com.google.common.base.Optional<java.lang.String> |
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) |
static java.lang.String |
getProtocol(java.lang.String url)
Deprecated.
since 0.7.0; use method
Urls.getProtocol(String) |
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.lang.Iterable<java.net.URL> |
getResources(java.lang.String name) |
static java.lang.String |
mergeFilePaths(java.lang.String... items)
Deprecated.
since 0.7.0; use method
Os.mergePaths(String...) |
static java.lang.String |
mergePaths(java.lang.String... items)
Deprecated.
since 0.7.0 use either
Os.mergePathsUnix(String...) {@link Urls#mergePaths(String...) |
static java.io.File |
mkdirs(java.io.File dir)
Deprecated.
since 0.7.0; use same method in
Os |
static byte[] |
readFullyBytes(java.io.InputStream is)
Deprecated.
since 0.7.0 use {@link Streams#readFully(InputStream)
|
static java.lang.String |
readFullyString(java.io.InputStream is)
Deprecated.
since 0.7.0 use {@link Streams#readFullyString(InputStream)
|
static boolean |
removeShutdownHook(java.lang.Thread hook)
Deprecated.
since 0.7.0; use method
Threads.removeShutdownHook(Thread) |
static java.net.URL |
tidy(java.net.URL url) |
static java.lang.String |
tidyFilePath(java.lang.String path)
Deprecated.
since 0.7.0; use method
Os.tidyPath(String) |
static java.lang.String |
tidyFileUrl(java.lang.String url) |
static java.io.File |
writeToTempFile(java.io.InputStream is,
java.io.File tempDir,
java.lang.String prefix,
java.lang.String suffix)
Deprecated.
since 0.7.0; use same method in
Os |
static java.io.File |
writeToTempFile(java.io.InputStream is,
java.lang.String prefix,
java.lang.String suffix)
Deprecated.
since 0.7.0; use same method in
Os |
static java.io.File |
writeToTempFile(java.util.Properties props,
java.io.File tempDir,
java.lang.String prefix,
java.lang.String suffix)
Deprecated.
since 0.7.0; use method
Os.writePropertiesToTempFile(Properties, File, String, String) |
static java.io.File |
writeToTempFile(java.util.Properties props,
java.lang.String prefix,
java.lang.String suffix)
Deprecated.
since 0.7.0; use method
Os.writePropertiesToTempFile(Properties, String, String) |
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(com.google.common.base.Function<java.lang.Object,BrooklynClassLoadingContext> 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)
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)
@Deprecated public static java.lang.String mergeFilePaths(java.lang.String... items)
Os.mergePaths(String...)
@Deprecated public static java.lang.String tidyFilePath(java.lang.String path)
Os.tidyPath(String)
@Deprecated public static java.lang.String getProtocol(java.lang.String url)
Urls.getProtocol(String)
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)
public java.lang.String checkUrlExists(java.lang.String url, java.lang.String message)
public boolean doesUrlExist(java.lang.String url)
public com.google.common.base.Optional<java.lang.String> 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)
@Deprecated public static java.lang.String readFullyString(java.io.InputStream is) throws java.io.IOException
java.io.IOException
@Deprecated public static byte[] readFullyBytes(java.io.InputStream is) throws java.io.IOException
java.io.IOException
@Deprecated public static void copy(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOException
Streams.copy(InputStream, OutputStream)
java.io.IOException
@Deprecated public static java.io.File mkdirs(java.io.File dir)
Os
@Deprecated public static java.io.File writeToTempFile(java.io.InputStream is, java.lang.String prefix, java.lang.String suffix)
Os
@Deprecated public static java.io.File writeToTempFile(java.io.InputStream is, java.io.File tempDir, java.lang.String prefix, java.lang.String suffix)
Os
@Deprecated public static java.io.File writeToTempFile(java.util.Properties props, java.lang.String prefix, java.lang.String suffix)
Os.writePropertiesToTempFile(Properties, String, String)
@Deprecated public static java.io.File writeToTempFile(java.util.Properties props, java.io.File tempDir, java.lang.String prefix, java.lang.String suffix)
Os.writePropertiesToTempFile(Properties, File, String, String)
@Deprecated public static java.lang.Thread addShutdownHook(java.lang.Runnable task)
Threads.addShutdownHook(Runnable)
@Deprecated public static boolean removeShutdownHook(java.lang.Thread hook)
Threads.removeShutdownHook(Thread)
@Deprecated public static java.lang.String mergePaths(java.lang.String... items)
Os.mergePathsUnix(String...)
{@link Urls#mergePaths(String...)