org.apache.shiro.io
Class ResourceUtils

java.lang.Object
  extended by org.apache.shiro.io.ResourceUtils

public class ResourceUtils
extends Object

Static helper methods for loading Stream-backed resources.

Since:
0.2
See Also:
getInputStreamForPath(String)

Field Summary
static String CLASSPATH_PREFIX
          Resource path prefix that specifies to load from a classpath location, value is classpath:
static String FILE_PREFIX
          Resource path prefix that specifies to load from a file location, value is file:
static String URL_PREFIX
          Resource path prefix that specifies to load from a url location, value is url:
 
Method Summary
static void close(InputStream is)
          Convenience method that closes the specified InputStream, logging any IOException that might occur.
static InputStream getInputStreamForPath(String resourcePath)
          Returns the InputStream for the resource represented by the specified path, supporting scheme prefixes that direct how to acquire the input stream (CLASSPATH_PREFIX, URL_PREFIX, or FILE_PREFIX).
static boolean hasResourcePrefix(String resourcePath)
          Returns true if the resource path is not null and starts with one of the recognized resource prefixes (CLASSPATH_PREFIX, URL_PREFIX, or FILE_PREFIX), false otherwise.
static boolean resourceExists(String resourcePath)
          Returns true if the resource at the specified path exists, false otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASSPATH_PREFIX

public static final String CLASSPATH_PREFIX
Resource path prefix that specifies to load from a classpath location, value is classpath:

See Also:
Constant Field Values

URL_PREFIX

public static final String URL_PREFIX
Resource path prefix that specifies to load from a url location, value is url:

See Also:
Constant Field Values

FILE_PREFIX

public static final String FILE_PREFIX
Resource path prefix that specifies to load from a file location, value is file:

See Also:
Constant Field Values
Method Detail

hasResourcePrefix

public static boolean hasResourcePrefix(String resourcePath)
Returns true if the resource path is not null and starts with one of the recognized resource prefixes (CLASSPATH_PREFIX, URL_PREFIX, or FILE_PREFIX), false otherwise.

Parameters:
resourcePath - the resource path to check
Returns:
true if the resource path is not null and starts with one of the recognized resource prefixes, false otherwise.
Since:
0.9

resourceExists

public static boolean resourceExists(String resourcePath)
Returns true if the resource at the specified path exists, false otherwise. This method supports scheme prefixes on the path as defined in getInputStreamForPath(String).

Parameters:
resourcePath - the path of the resource to check.
Returns:
true if the resource at the specified path exists, false otherwise.
Since:
0.9

getInputStreamForPath

public static InputStream getInputStreamForPath(String resourcePath)
                                         throws IOException
Returns the InputStream for the resource represented by the specified path, supporting scheme prefixes that direct how to acquire the input stream (CLASSPATH_PREFIX, URL_PREFIX, or FILE_PREFIX). If the path is not prefixed by one of these schemes, the path is assumed to be a file-based path that can be loaded with a FileInputStream.

Parameters:
resourcePath - the String path representing the resource to obtain.
Returns:
the InputStraem for the specified resource.
Throws:
IOException - if there is a problem acquiring the resource at the specified path.

close

public static void close(InputStream is)
Convenience method that closes the specified InputStream, logging any IOException that might occur. If the InputStream argument is null, this method does nothing. It returns quietly in all cases.

Parameters:
is - the InputStream to close, logging any IOException that might occur.


Copyright © 2004-2012 The Apache Software Foundation. All Rights Reserved.