You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2014/12/23 15:52:41 UTC
[2/2] cxf git commit: Add utility to determin if filename is valid
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 <dk...@apache.org>
Authored: Tue Dec 23 09:51:06 2014 -0500
Committer: Daniel Kulp <dk...@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()) {