Brooklyn

brooklyn.util
[Java] Class ResourceUtils

java.lang.Object
  brooklyn.util.ResourceUtils

public class ResourceUtils

Constructor Summary
ResourceUtils(java.lang.ClassLoader loader, java.lang.String context)

context string 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 java.lang.Thread addShutdownHook(java.lang.Runnable task)

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

java.lang.ClassLoader getLoader()

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

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.io.File writeToTempFile(java.io.InputStream is, 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.String context)
context string used for errors


ResourceUtils

@SuppressWarnings("rawtypes")
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

addShutdownHook

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


copy

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


getLoader

public java.lang.ClassLoader getLoader()


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


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)


writeToTempFile

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


 

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