Move #checkFileName() to Files because it doesn't deal with IO streams
Actually execute the check.
Fix Javadoc problems.
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/file/Files.java b/wicket-util/src/main/java/org/apache/wicket/util/file/Files.java
index 4e89a7b..8408b6f 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/file/Files.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/file/Files.java
@@ -26,6 +26,7 @@
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
+import java.security.InvalidParameterException;
import org.apache.wicket.util.io.IOUtils;
import org.apache.wicket.util.io.Streams;
@@ -471,4 +472,39 @@
logger.error("Failed to create directory: " + folder);
return false;
}
+
+ /**
+ * Checks, whether the given file name is valid in the sense, that it
+ * doesn't contain any NUL characters. If the file name is valid, it will be
+ * returned without any modifications. Otherwise, an
+ * {@link InvalidParameterException} will be thrown.
+ *
+ * @param fileName
+ * The file name to check
+ * @return Unmodified file name, if valid.
+ * @throws InvalidParameterException
+ * If the file name was found to be invalid.
+ */
+ public static String checkFileName(String fileName)
+ {
+ if (fileName != null && fileName.indexOf('\u0000') != -1)
+ {
+ final StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < fileName.length(); i++)
+ {
+ char c = fileName.charAt(i);
+ switch (c)
+ {
+ case 0 :
+ sb.append("\\0");
+ break;
+ default :
+ sb.append(c);
+ break;
+ }
+ }
+ throw new InvalidParameterException("Invalid file name: " + sb);
+ }
+ return fileName;
+ }
}
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java b/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java
index f2fc907..1c4519d 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java
@@ -206,41 +206,6 @@
}
/**
- * Checks, whether the given file name is valid in the sense, that it
- * doesn't contain any NUL characters. If the file name is valid, it will be
- * returned without any modifications. Otherwise, an
- * {@link InvalidFileNameException} is raised.
- *
- * @param fileName
- * The file name to check
- * @return Unmodified file name, if valid.
- * @throws InvalidFileNameException
- * The file name was found to be invalid.
- */
- public static String checkFileName(String fileName)
- {
- if (fileName != null && fileName.indexOf('\u0000') != -1)
- {
- final StringBuilder sb = new StringBuilder();
- for (int i = 0; i < fileName.length(); i++)
- {
- char c = fileName.charAt(i);
- switch (c)
- {
- case 0 :
- sb.append("\\0");
- break;
- default :
- sb.append(c);
- break;
- }
- }
- throw new InvalidParameterException("Invalid file name: " + sb);
- }
- return fileName;
- }
-
- /**
* Private to prevent instantiation.
*/
private Streams()
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/upload/DiskFileItem.java b/wicket-util/src/main/java/org/apache/wicket/util/upload/DiskFileItem.java
index 5ad6350..c4ec5ae 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/upload/DiskFileItem.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/upload/DiskFileItem.java
@@ -48,8 +48,8 @@
*
* <p>
* After retrieving an instance of this class from a
- * {@link org.apache.wicket.util.upload.DiskFileUpload DiskFileUpload} instance (see
- * {@link org.apache.wicket.util.upload.DiskFileUpload #parseRequest(javax.servlet.http.HttpServletRequest)}
+ * {@link org.apache.wicket.util.upload.FileUpload DiskFileUpload} instance (see
+ * {@link org.apache.wicket.util.upload.FileUpload#parseRequest(RequestContext)}
* ), you may either request all contents of file at once using {@link #get()} or request an
* {@link java.io.InputStream InputStream} with {@link #getInputStream()} and process the file
* without attempting to load it into memory, which may come handy with large files.
@@ -59,7 +59,7 @@
* Temporary files are automatically deleted as soon as they are no longer needed. (More precisely,
* when the corresponding instance of {@link java.io.File} is garbage collected.) This is done by
* the so-called reaper thread, which is started automatically when the class
- * {@link org.apache.commons.io.FileCleaner} is loaded. It might make sense to terminate that
+ * {@link org.apache.wicket.util.file.FileCleaner} is loaded. It might make sense to terminate that
* thread, for example, if your web application ends. See the section on "Resource cleanup" in the
* users guide of commons-fileupload.
* </p>
@@ -601,11 +601,7 @@
File tempDir = repository;
if (tempDir == null)
{
- if (repository != null)
- {
- Streams.checkFileName(repository.getPath());
- }
- String systemTmp = null;
+ String systemTmp;
try
{
systemTmp = System.getProperty("java.io.tmpdir");
@@ -620,6 +616,8 @@
tempDir = new File(systemTmp);
}
+ Files.checkFileName(tempDir.getPath());
+
try
{
do