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 2015/03/14 08:15:58 UTC

[3/8] camel git commit: CAMEL-8484: File language - Should support file extensions with multiple dots such as tar.gz

CAMEL-8484: File language - Should support file extensions with multiple dots such as tar.gz


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

Branch: refs/heads/master
Commit: b8590c834a0855c22870085fb132f21eccb3c474
Parents: 5174a1c
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Mar 14 08:16:17 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Mar 14 08:16:17 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/camel/util/FileUtil.java    | 22 +++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b8590c83/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
index d3db672..8500d9a 100644
--- a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
@@ -194,13 +194,25 @@ public final class FileUtil {
         if (name == null) {
             return null;
         }
-        name = stripPath(name);
 
-        // extension is the first dot, as a file may have double extension such as .tar.gz
-        int pos = name.indexOf('.');
-        if (pos != -1) {
-            return name.substring(0, pos);
+        // the name may have a leading path
+        int posUnix = name.lastIndexOf('/');
+        int posWin = name.lastIndexOf('\\');
+        int pos = Math.max(posUnix, posWin);
+
+        if (pos > 0) {
+            String onlyName = name.substring(pos + 1);
+            int pos2 = onlyName.indexOf('.');
+            if (pos2 > 0) {
+                return name.substring(0, pos + pos2 + 1);
+            }
+        } else {
+            int pos2 = name.indexOf('.');
+            if (pos2 > 0) {
+                return name.substring(0, pos2);
+            }
         }
+
         return name;
     }