lprimak commented on code in PR #2018:
URL: https://github.com/apache/shiro/pull/2018#discussion_r2710752944


##########
lang/src/main/java/org/apache/shiro/lang/util/ClassUtils.java:
##########
@@ -118,42 +120,66 @@ private ClassUtils() {
      * @param name the name of the resource to acquire from the classloader(s).
      * @return the InputStream of the resource found, or <code>null</code> if 
the resource cannot be found from any
      * of the three mentioned ClassLoaders.
+     * @see #getResource(String)
      * @since 0.9
      */
     public static InputStream getResourceAsStream(String name) {
+        URL url = getResource(name);
+        if (url == null) {
+            return null;
+        }
 
-        InputStream is = THREAD_CL_ACCESSOR.getResourceStream(name);
+        try {
+            return url.openStream();
+        } catch (IOException e) {
+            return null;
+        }
+    }
 
-        if (is == null) {
+    /**
+     * Returns the specified resource by checking the current thread's
+     * {@link Thread#getContextClassLoader() context class loader}, then the
+     * current ClassLoader (<code>ClassUtils.class.getClassLoader()</code>), 
then the system/application
+     * ClassLoader (<code>ClassLoader.getSystemClassLoader()</code>, in that 
order, using
+     * {@link ClassLoader#getResource(String) getResource(name)}.
+     *
+     * @param name the name of the resource to acquire from the classloader(s).
+     * @return the URL of the resource found, or <code>null</code> if the 
resource cannot be found from any
+     * of the three mentioned ClassLoaders.
+     * @since 3.0
+     */
+    public static URL getResource(String name) {
+        URL url = THREAD_CL_ACCESSOR.getResource(name);

Review Comment:
   I am not quite sure what this change is for...
   Can you elaborate please?



##########
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:
   I am not quite sure what this change is for...
   Can you elaborate please?



##########
lang/src/main/java/org/apache/shiro/lang/util/ClassUtils.java:
##########
@@ -347,6 +375,15 @@ public InputStream getResourceStream(String name) {
             return is;
         }
 
+        public URL getResource(String name) {
+            URL url = null;

Review Comment:
   I am not quite sure what this change is for...
   Can you elaborate please?



-- 
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]

Reply via email to