Class ResourceUtils
java.lang.Object
org.apache.shiro.lang.io.ResourceUtils
Static helper methods for loading
Stream-backed resources.- Since:
- 0.2
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringResource path prefix that specifies to load from a classpath location, value isclasspath:static final StringResource path prefix that specifies to load from a file location, value isfile:static final StringResource path prefix that specifies to load from a url location, value isurl: -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclose(InputStream is) Convenience method that closes the specifiedInputStream, logging anyIOExceptionthat might occur.static InputStreamgetInputStreamForPath(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, orFILE_PREFIX).static booleanhasResourcePrefix(String resourcePath) Returnstrueif the resource path is not null and starts with one of the recognized resource prefixes (CLASSPATH_PREFIX,URL_PREFIX, orFILE_PREFIX),falseotherwise.static booleanresourceExists(String resourcePath) Returnstrueif the resource at the specified path exists,falseotherwise.
-
Field Details
-
CLASSPATH_PREFIX
Resource path prefix that specifies to load from a classpath location, value isclasspath:- See Also:
-
URL_PREFIX
Resource path prefix that specifies to load from a url location, value isurl:- See Also:
-
FILE_PREFIX
Resource path prefix that specifies to load from a file location, value isfile:- See Also:
-
-
Method Details
-
hasResourcePrefix
Returnstrueif the resource path is not null and starts with one of the recognized resource prefixes (CLASSPATH_PREFIX,URL_PREFIX, orFILE_PREFIX),falseotherwise.- Parameters:
resourcePath- the resource path to check- Returns:
trueif the resource path is not null and starts with one of the recognized resource prefixes,falseotherwise.- Since:
- 0.9
-
resourceExists
Returnstrueif the resource at the specified path exists,falseotherwise. This method supports scheme prefixes on the path as defined ingetInputStreamForPath(String).- Parameters:
resourcePath- the path of the resource to check.- Returns:
trueif the resource at the specified path exists,falseotherwise.- Since:
- 0.9
-
getInputStreamForPath
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, orFILE_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 aFileInputStream.- Parameters:
resourcePath- the String path representing the resource to obtain.- Returns:
- the InputStream for the specified resource.
- Throws:
IOException- if there is a problem acquiring the resource at the specified path.
-
close
Convenience method that closes the specifiedInputStream, logging anyIOExceptionthat might occur. If theInputStreamargument isnull, this method does nothing. It returns quietly in all cases.- Parameters:
is- theInputStreamto close, logging anyIOExceptionthat might occur.
-