Package org.apache.shiro.io
Class ResourceUtils
- java.lang.Object
-
- org.apache.shiro.io.ResourceUtils
-
public class ResourceUtils extends Object
Static helper methods for loadingStream-backed resources.- Since:
- 0.2
- See Also:
getInputStreamForPath(String)
-
-
Field Summary
Fields Modifier and Type Field Description static StringCLASSPATH_PREFIXResource path prefix that specifies to load from a classpath location, value isclasspath:static StringFILE_PREFIXResource path prefix that specifies to load from a file location, value isfile:static StringURL_PREFIXResource path prefix that specifies to load from a url location, value isurl:
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 Detail
-
CLASSPATH_PREFIX
public static final String CLASSPATH_PREFIX
Resource path prefix that specifies to load from a classpath location, value isclasspath:- 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 isurl:- 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 isfile:- See Also:
- Constant Field Values
-
-
Method Detail
-
hasResourcePrefix
public static boolean hasResourcePrefix(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.- 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
public static boolean resourceExists(String resourcePath)
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
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, 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
public static void close(InputStream is)
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.
-
-