rgcv commented on code in PR #2018:
URL: https://github.com/apache/shiro/pull/2018#discussion_r2711711339
##########
lang/src/main/java/org/apache/shiro/lang/io/ResourceUtils.java:
##########
@@ -120,25 +121,45 @@ public static boolean resourceExists(String resourcePath)
{
*/
public static InputStream getInputStreamForPath(String resourcePath)
throws IOException {
- InputStream is;
- if (resourcePath.startsWith(CLASSPATH_PREFIX)) {
- is = loadFromClassPath(stripPrefix(resourcePath));
+ URL url = getURLForPath(resourcePath);
+ if (url == null) {
+ throw new IOException("Resource [" + resourcePath + "] could not
be found.");
+ }
- } else if (resourcePath.startsWith(URL_PREFIX)) {
- is = loadFromUrl(stripPrefix(resourcePath));
+ return url.openStream();
+ }
- } else if (resourcePath.startsWith(FILE_PREFIX)) {
- is = loadFromFile(stripPrefix(resourcePath));
+ /**
+ * Returns the URL for the resource represented by the specified path,
supporting scheme
+ * prefixes that direct how to acquire the input stream
+ * ({@link #CLASSPATH_PREFIX CLASSPATH_PREFIX},
+ * {@link #URL_PREFIX URL_PREFIX}, or {@link #FILE_PREFIX 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
+ * call to {@link URI#create(String)}.
+ *
+ * @param resourcePath the String path representing the resource to obtain.
+ * @return the URL for the specified resource.
+ * @throws IOException if there is a problem acquiring the resource at the
specified path.
+ */
+ public static URL getURLForPath(String resourcePath) throws IOException {
+ URL url;
+ if (resourcePath.startsWith(CLASSPATH_PREFIX)) {
Review Comment:
It's hard to recall why I did this, but I traced back to usages of these new
implementations that derive a resource's `URL`. Looks like in Ehcache 3, to
create an XmlConfiguration object, either a `URL` or a `org.w3c.dom.Document`
is required for construction. The rationale at the time was to both repurpose
the existing utilities and introduce a utility that handled `URL`s instead of
`InputStream`s to serve this new purpose.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]