You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:35:41 UTC

[sling-org-apache-sling-fsresource] 21/25: Check whether the abstract file is a directory before trying to open the FileInputStream on it (to prevent a nasty log message)

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git

commit 71d0b661f343fc6dc465b2f091e9dcf49e1d617a
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Thu Jan 21 12:06:45 2010 +0000

    Check whether the abstract file is a directory before trying to open the FileInputStream on it (to prevent a nasty log message)
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/fsresource@901668 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/fsprovider/internal/FsResource.java      | 24 ++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java b/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java
index f214c7f..372d499 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java
@@ -144,12 +144,22 @@ public class FsResource extends SlingAdaptable implements Resource {
 
             return (AdapterType) file;
 
-        } else if (type == InputStream.class && file.canRead()) {
+        } else if (type == InputStream.class) {
+
+            if (!file.isDirectory() && file.canRead()) {
+
+                try {
+                    return (AdapterType) new FileInputStream(file);
+                } catch (IOException ioe) {
+                    getLog().info(
+                        "adaptTo: Cannot open a stream on the file " + file,
+                        ioe);
+                }
+
+            } else {
+
+                getLog().debug("adaptTo: File {} is not a readable file", file);
 
-            try {
-                return (AdapterType) new FileInputStream(file);
-            } catch (IOException ioe) {
-                getLog().info("Cannot open a stream on the file " + file, ioe);
             }
 
         } else if (type == URL.class) {
@@ -158,8 +168,10 @@ public class FsResource extends SlingAdaptable implements Resource {
                 return (AdapterType) file.toURI().toURL();
             } catch (MalformedURLException mue) {
                 getLog().info(
-                    "Cannot convert the file path " + file + " to an URL", mue);
+                    "adaptTo: Cannot convert the file path " + file
+                        + " to an URL", mue);
             }
+
         }
 
         return super.adaptTo(type);

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.