camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [6/8] camel git commit: CAMEL-8484: File language - Should support file extensions with multiple dots such as tar.gz
Date Sat, 14 Mar 2015 07:16:01 GMT
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/b668a89a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b668a89a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b668a89a

Branch: refs/heads/camel-2.15.x
Commit: b668a89af613a464856d24b57aa860a320bba47d
Parents: 0aafc25
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Mar 14 08:16:17 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Mar 14 08:17:30 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/b668a89a/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;
     }
 


Mime
View raw message