ccc.commons
Class Resources

java.lang.Object
  extended by ccc.commons.Resources

public final class Resources
extends java.lang.Object

Helper methods for handling external resources.

Author:
Civic Computing Ltd

Field Summary
static java.nio.charset.Charset UTF8
          UTF8 : Charset.
 
Method Summary
static java.io.InputStream open(java.lang.String resourcePath)
          Open an input stream on a resource.
static java.util.List<java.lang.String> readIntoList(java.lang.String resourcePath, java.nio.charset.Charset charset)
          Read a resource path into memory as a list of strings.
static java.util.Properties readIntoProps(java.lang.String resourcePath)
          Read a resource path into memory as properties.
static java.lang.String readIntoString(java.io.InputStream is, java.nio.charset.Charset charset)
          Read an input stream into memory as a string.
static java.lang.String readIntoString(java.net.URL url, java.nio.charset.Charset charset)
          Read a URL resource into memory as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UTF8

public static final java.nio.charset.Charset UTF8
UTF8 : Charset.

Method Detail

readIntoString

public static java.lang.String readIntoString(java.net.URL url,
                                              java.nio.charset.Charset charset)
Read a URL resource into memory as a string.

Parameters:
url - The url to read from.
charset - The character set to use when reading the url.
Returns:
The resource as a String.

readIntoString

public static java.lang.String readIntoString(java.io.InputStream is,
                                              java.nio.charset.Charset charset)
Read an input stream into memory as a string.

Parameters:
is - The input stream to read from.
charset - The character set to use when reading the url.
Returns:
The resource as a String.

readIntoProps

public static java.util.Properties readIntoProps(java.lang.String resourcePath)
Read a resource path into memory as properties.

Parameters:
resourcePath - The absolute, '/'-separated path to the resource.
Returns:
The resource as a properties object.

readIntoList

public static java.util.List<java.lang.String> readIntoList(java.lang.String resourcePath,
                                                            java.nio.charset.Charset charset)
Read a resource path into memory as a list of strings.

One string per line in the resource.

Parameters:
resourcePath - The absolute, '/'-separated path to the resource.
charset - The character set to use when reading the resource.
Returns:
The resource as a list of strings.

open

public static java.io.InputStream open(java.lang.String resourcePath)
Open an input stream on a resource.

Parameters:
resourcePath - The absolute, '/'-separated path to the resource.
Returns:
An input stream onto the specified resource.


Copyright © 2010. All Rights Reserved.