cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [2/3] cxf git commit: Add utility to determin if filename is valid
Date Tue, 23 Dec 2014 14:54:56 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/60d7bf2e
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/60d7bf2e
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/60d7bf2e

Branch: refs/heads/3.0.x-fixes
Commit: 60d7bf2ef1d46516c1b1b921dc1a07de05856124
Parents: 94e4d75
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:54:38 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/60d7bf2e/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