Brooklyn

brooklyn.util
[Java] Class ResourceUtils

java.lang.Object
  brooklyn.util.ResourceUtils

public class ResourceUtils

Constructor Summary
ResourceUtils(java.lang.ClassLoader loader, java.lang.Object contextObject, java.lang.String contextMessage)

ResourceUtils(java.lang.Object contextObject, java.lang.String contextMessage)

ResourceUtils(java.lang.Object contextObject)

 
Method Summary
static void addClassLoaderProvider(Function provider)

used to register custom mechanisms for getting classloaders given an object

static java.lang.Thread addShutdownHook(java.lang.Runnable task)

java.lang.String checkUrlExists(java.lang.String url)

tests whether the url exists, returning true or false

static void copy(java.io.InputStream input, java.io.OutputStream output)

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, java.lang.String contextMessage)

Creates a ResourceUtils object with the given context.

static ResourceUtils create(java.lang.Object contextObject)

Creates a ResourceUtils object with the given context.

static ResourceUtils create()

Creates a ResourceUtils object with itself as the context.

boolean doesUrlExist(java.lang.String url)

returns the first available URL

Optional firstAvailableUrl(java.lang.String... urls)

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 getClassLoaderDir(java.lang.String resourceInThatDir)

static java.lang.ClassLoader getClassLoaderForObject(java.lang.Object contextObject)

java.lang.ClassLoader getLoader()

static java.lang.String getProtocol(java.lang.String url)

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)

static java.lang.String mergeFilePaths(java.lang.String... items)

static java.lang.String mergePaths(java.lang.String... items)

static java.io.File mkdirs(java.io.File dir)

static byte[] readFullyBytes(java.io.InputStream is)

static java.lang.String readFullyString(java.io.InputStream is)

static boolean removeShutdownHook(java.lang.Thread hook)

returns the items with exactly one "/" between items (whether or not the individual items start or end with /), except where character before the / is a : (url syntax) in which case it will permit multiple (will not remove any)

static java.net.URL tidy(java.net.URL url)

static java.lang.String tidyFilePath(java.lang.String path)

static java.lang.String tidyFileUrl(java.lang.String url)

static java.io.File writeToTempFile(java.io.InputStream is, java.lang.String prefix, java.lang.String suffix)

static java.io.File writeToTempFile(java.io.InputStream is, java.io.File tempDir, java.lang.String prefix, java.lang.String suffix)

static java.io.File writeToTempFile(java.util.Properties props, java.lang.String prefix, java.lang.String suffix)

static java.io.File writeToTempFile(java.util.Properties props, java.io.File tempDir, java.lang.String prefix, java.lang.String suffix)

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Constructor Detail

ResourceUtils

public ResourceUtils(java.lang.ClassLoader loader, java.lang.Object contextObject, java.lang.String contextMessage)


ResourceUtils

public ResourceUtils(java.lang.Object contextObject, java.lang.String contextMessage)


ResourceUtils

public ResourceUtils(java.lang.Object contextObject)


 
Method Detail

addClassLoaderProvider

public static void addClassLoaderProvider(Function provider)
used to register custom mechanisms for getting classloaders given an object


addShutdownHook

public static java.lang.Thread addShutdownHook(java.lang.Runnable task)


checkUrlExists

public java.lang.String checkUrlExists(java.lang.String url)
tests whether the url exists, returning true or false


copy

public static void copy(java.io.InputStream input, java.io.OutputStream output)


create

public static final 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.

Use the provided java.lang.ClassLoader object for class loading with the contextObject for context and the contextMessage string for error messages.

See Also:
ResourceUtils#create(Object, String)#create(Object, String)
ResourceUtils#create(Object)#create(Object)


create

public static final ResourceUtils create(java.lang.Object contextObject, java.lang.String contextMessage)
Creates a ResourceUtils object with the given context.

Uses the java.lang.ClassLoader of the given contextObject for class loading and the contextMessage string for error messages.

See Also:
ResourceUtils#create(ClassLoader, Object, String)#create(ClassLoader, Object, String)
ResourceUtils#create(Object)#create(Object)


create

public static final ResourceUtils create(java.lang.Object contextObject)
Creates a ResourceUtils object with the given context.

Uses the java.lang.ClassLoader of the given contextObject for class loading and its java.lang.Object#toString() (preceded by the word 'for') as the string used in error messages.

See Also:
ResourceUtils#create(ClassLoader, Object, String)#create(ClassLoader, Object, String)
ResourceUtils#create(Object)#create(Object)


create

public static final ResourceUtils create()
Creates a ResourceUtils object with itself as the context.
See Also:
ResourceUtils#create(Object)#create(Object)


doesUrlExist

public boolean doesUrlExist(java.lang.String url)
returns the first available URL


firstAvailableUrl

public Optional firstAvailableUrl(java.lang.String... urls)
returns the base directory or JAR from which the context is class-loaded, if possible; throws exception if not found


getClassLoaderDir

public java.lang.String getClassLoaderDir()


getClassLoaderDir

public java.lang.String getClassLoaderDir(java.lang.String resourceInThatDir)


getClassLoaderForObject

public static java.lang.ClassLoader getClassLoaderForObject(java.lang.Object contextObject)


getLoader

public java.lang.ClassLoader getLoader()


getProtocol

public static java.lang.String getProtocol(java.lang.String url)


getResourceAsString

public java.lang.String getResourceAsString(java.lang.String url)
takes getResourceFromUrl(String) and reads fully, into a string


getResourceFromUrl

public 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)

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

Returns:
a stream, or throws exception (never returns null)


mergeFilePaths

public static java.lang.String mergeFilePaths(java.lang.String... items)


mergePaths

public static java.lang.String mergePaths(java.lang.String... items)


mkdirs

public static java.io.File mkdirs(java.io.File dir)


readFullyBytes

public static byte[] readFullyBytes(java.io.InputStream is)


readFullyString

public static java.lang.String readFullyString(java.io.InputStream is)


removeShutdownHook

public static boolean removeShutdownHook(java.lang.Thread hook)
returns the items with exactly one "/" between items (whether or not the individual items start or end with /), except where character before the / is a : (url syntax) in which case it will permit multiple (will not remove any)


tidy

public static java.net.URL tidy(java.net.URL url)


tidyFilePath

public static java.lang.String tidyFilePath(java.lang.String path)


tidyFileUrl

public static java.lang.String tidyFileUrl(java.lang.String url)


writeToTempFile

public static java.io.File writeToTempFile(java.io.InputStream is, java.lang.String prefix, java.lang.String suffix)


writeToTempFile

public static java.io.File writeToTempFile(java.io.InputStream is, java.io.File tempDir, java.lang.String prefix, java.lang.String suffix)


writeToTempFile

public static java.io.File writeToTempFile(java.util.Properties props, java.lang.String prefix, java.lang.String suffix)


writeToTempFile

public static java.io.File writeToTempFile(java.util.Properties props, java.io.File tempDir, java.lang.String prefix, java.lang.String suffix)


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.