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)

context string used for errors

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

contextObject used for classloading, contextMessage used for errors

ResourceUtils(java.lang.Object context)

uses the classloader of the given object, and the phrase object's toString (preceded by the word 'for') as the context string used in errors

 
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)

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

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.lang.ClassLoader getClassLoaderForObject(java.lang.Object contextObject)

java.lang.ClassLoader getLoader()

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

returns the protocol (e.g. http) if one appears to be specified, or else null; 'protocol' here should consist of 2 or more _letters_ only followed by a colon (2 required to prevent c``:\xxx being treated as a 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 mergePaths(java.lang.String... items)

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

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

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)
context string used for errors


ResourceUtils

public ResourceUtils(java.lang.Object contextObject, java.lang.String contextMessage)
contextObject used for classloading, contextMessage used for errors


ResourceUtils

public ResourceUtils(java.lang.Object context)
uses the classloader of the given object, and the phrase object's toString (preceded by the word 'for') as the context string used in errors


 
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)


copy

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


getClassLoaderDir

public java.lang.String getClassLoaderDir()
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(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)
returns the protocol (e.g. http) if one appears to be specified, or else null; 'protocol' here should consist of 2 or more _letters_ only followed by a colon (2 required to prevent c``:\xxx being treated as a 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)


mergePaths

public static java.lang.String mergePaths(java.lang.String... items)
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)


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)


tidy

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


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.