cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [2/2] cxf git commit: Add utility to determin if filename is valid
Date Tue, 23 Dec 2014 14:52:41 GMT
Add utility to determin if filename is valid


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

Branch: refs/heads/master
Commit: 5e017ce4d98d2dacb3578ee6fa9579fac2779f8a
Parents: 40c6734
Author: Daniel Kulp <dkulp@apache.org>
Authored: Tue Dec 23 09:51:06 2014 -0500
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Tue Dec 23 09:52:34 2014 -0500

----------------------------------------------------------------------
 .../java/org/apache/cxf/helpers/FileUtils.java  | 27 +++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/5e017ce4/core/src/main/java/org/apache/cxf/helpers/FileUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/helpers/FileUtils.java b/core/src/main/java/org/apache/cxf/helpers/FileUtils.java
index 2bafee2..82444d1 100644
--- a/core/src/main/java/org/apache/cxf/helpers/FileUtils.java
+++ b/core/src/main/java/org/apache/cxf/helpers/FileUtils.java
@@ -38,12 +38,37 @@ import org.apache.cxf.common.util.SystemPropertyAction;
 public final class FileUtils {
     private static final int RETRY_SLEEP_MILLIS = 10;
     private static File defaultTempDir;
-    
+    private static final char[] ILLEGAL_CHARACTERS 
+        = {'/', '\n', '\r', '\t', '\0', '\f', '`', '?', '*', '\\', '<', '>', '|', '\"',
':'};    
     
     private FileUtils() {
         
     }
     
+    public boolean isValidFileName(String name) {
+        for (int i = name.length(); i > 0; i--) {
+            char c = name.charAt(i - 1);
+            for (char c2 : ILLEGAL_CHARACTERS) {
+                if (c == c2) {
+                    return false;
+                }
+            }
+        }
+        File file = new File(getDefaultTempDir(), name);
+        boolean isValid = true;
+        try {
+            if (file.exists()) {
+                return true;
+            }
+            if (file.createNewFile()) {
+                file.delete();
+            }
+        } catch (IOException e) {
+            isValid = false;
+        }
+        return isValid;
+    }
+
     public static synchronized File getDefaultTempDir() {
         if (defaultTempDir != null
             && defaultTempDir.exists()) {


Mime
View raw message