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:59 UTC

[4/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/8ac06507
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8ac06507
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8ac06507

Branch: refs/heads/camel-2.14.x
Commit: 8ac0650748879329ef66bdacd5f2c05b9ffff048
Parents: bb3e510
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:17:13 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/8ac06507/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;
     }