camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] git commit: CAMEL-6689: Polished
Date Sun, 24 Nov 2013 08:21:24 GMT
CAMEL-6689: Polished


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3b8d80d2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3b8d80d2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3b8d80d2

Branch: refs/heads/camel-2.12.x
Commit: 3b8d80d2df332daf417454a12a3aa89257735f42
Parents: b347ad0
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Nov 24 09:21:33 2013 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Nov 24 09:21:59 2013 +0100

----------------------------------------------------------------------
 .../org/apache/camel/util/ResourceHelper.java   | 45 +++++++++-----------
 1 file changed, 21 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3b8d80d2/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java b/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java
index 1609918..15ceefc 100644
--- a/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java
@@ -106,12 +106,7 @@ public final class ResourceHelper {
     public static InputStream resolveResourceAsInputStream(ClassResolver classResolver, String
uri) throws IOException {
         if (uri.startsWith("file:")) {
             uri = ObjectHelper.after(uri, "file:");
-            try {
-                // try to decode as the uri may contain %20 for spaces etc
-                uri = URLDecoder.decode(uri, "UTF-8");
-            } catch (Exception e) {
-                // ignore
-            }
+            uri = tryDecodeUri(uri);
             LOG.trace("Loading resource: {} from file system", uri);
             return new FileInputStream(uri);
         } else if (uri.startsWith("http:")) {
@@ -130,13 +125,8 @@ public final class ResourceHelper {
                 throw e;
             }
         } else if (uri.startsWith("classpath:")) {
-            try {
-                // try to decode as the uri may contain %20 for spaces etc
-                uri = URLDecoder.decode(uri, "UTF-8");
-            } catch (Exception e) {
-                // ignore
-            }
             uri = ObjectHelper.after(uri, "classpath:");
+            uri = tryDecodeUri(uri);
         }
 
         // load from classpath by default
@@ -176,12 +166,7 @@ public final class ResourceHelper {
         if (uri.startsWith("file:")) {
             // check if file exists first
             String name = ObjectHelper.after(uri, "file:");
-            try {
-                // try to decode as the uri may contain %20 for spaces etc
-                uri = URLDecoder.decode(uri, "UTF-8");
-            } catch (Exception e) {
-                // ignore
-            }
+            uri = tryDecodeUri(uri);
             LOG.trace("Loading resource: {} from file system", uri);
             File file = new File(name);
             if (!file.exists()) {
@@ -193,12 +178,7 @@ public final class ResourceHelper {
             return new URL(uri);
         } else if (uri.startsWith("classpath:")) {
             uri = ObjectHelper.after(uri, "classpath:");
-            try {
-                // try to decode as the uri may contain %20 for spaces etc
-                uri = URLDecoder.decode(uri, "UTF-8");
-            } catch (Exception e) {
-                // ignore
-            }
+            uri = tryDecodeUri(uri);
         }
 
         // load from classpath by default
@@ -254,4 +234,21 @@ public final class ResourceHelper {
         return FileUtil.compactPath(name, '/');
     }
 
+    /**
+     * Tries decoding the uri.
+     *
+     * @param uri the uri
+     * @return the decoded uri, or the original uri
+     */
+    private static String tryDecodeUri(String uri) {
+        try {
+            // try to decode as the uri may contain %20 for spaces etc
+            uri = URLDecoder.decode(uri, "UTF-8");
+        } catch (Exception e) {
+            LOG.trace("Error URL decoding uri using UTF-8 encoding: {}. This exception is
ignored.", uri);
+            // ignore
+        }
+        return uri;
+    }
+
 }


Mime
View raw message