You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/11/24 09:21:25 UTC
[3/3] git commit: CAMEL-6689: Polished
CAMEL-6689: Polished
Conflicts:
camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3457faa6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3457faa6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3457faa6
Branch: refs/heads/camel-2.11.x
Commit: 3457faa61370049d643bd535c9f3f4463beabf89
Parents: 4aeb44a
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Nov 24 09:21:33 2013 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Nov 24 09:22:57 2013 +0100
----------------------------------------------------------------------
.../org/apache/camel/util/ResourceHelper.java | 44 +++++++++-----------
1 file changed, 20 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3457faa6/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 f9b3258..a991c0b 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
@@ -82,12 +82,7 @@ public final class ResourceHelper {
public static InputStream resolveMandatoryResourceAsInputStream(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);
return new FileInputStream(uri);
} else if (uri.startsWith("http:")) {
URL url = new URL(uri);
@@ -104,13 +99,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
@@ -136,12 +126,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);
File file = new File(name);
if (!file.exists()) {
throw new FileNotFoundException("File " + file + " not found");
@@ -151,12 +136,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
@@ -215,4 +195,20 @@ 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) {
+ // ignore
+ }
+ return uri;
+ }
+
}