commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joc...@apache.org
Subject svn commit: r578253 - in /commons/proper/fileupload/trunk: ./ src/java/org/apache/commons/fileupload/ src/java/org/apache/commons/fileupload/disk/ src/java/org/apache/commons/fileupload/servlet/ src/java/org/apache/commons/fileupload/util/ src/test/org...
Date Fri, 21 Sep 2007 20:13:15 GMT
Author: jochen
Date: Fri Sep 21 13:13:14 2007
New Revision: 578253

URL: http://svn.apache.org/viewvc?rev=578253&view=rev
Log:
Partially backing out r518775, in order to get rid of the problems with FileItem implementing
Serializable.

Modified:
    commons/proper/fileupload/trunk/.project
    commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileItem.java
    commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileItemHeaders.java
    commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ParameterParser.java
    commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/disk/DiskFileItem.java
    commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/disk/DiskFileItemFactory.java
    commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/servlet/FileCleanerCleanup.java
    commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/util/FileItemHeadersImpl.java
    commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/DiskFileItemSerializeTest.java
    commons/proper/fileupload/trunk/xdocs/using.xml

Modified: commons/proper/fileupload/trunk/.project
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/.project?rev=578253&r1=578252&r2=578253&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/.project (original)
+++ commons/proper/fileupload/trunk/.project Fri Sep 21 13:13:14 2007
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-	<name>commons-fileupload</name>
+	<name>commons-fileupload-1.2</name>
 	<comment>The FileUpload component provides a simple yet flexible means of adding support
for multipart file upload functionality to servlets and web applications.</comment>
 	<projects>
 	</projects>
@@ -15,9 +15,15 @@
 			<arguments>
 			</arguments>
 		</buildCommand>
+		<buildCommand>
+			<name>org.devzuz.q.maven.jdt.core.mavenIncrementalBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
 	</buildSpec>
 	<natures>
-		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.devzuz.q.maven.jdt.core.mavenNature</nature>
 		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
 	</natures>
 </projectDescription>

Modified: commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileItem.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileItem.java?rev=578253&r1=578252&r2=578253&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileItem.java (original)
+++ commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileItem.java Fri
Sep 21 13:13:14 2007
@@ -50,8 +50,7 @@
  *
  * @version $Id$
  */
-public interface FileItem
-    extends Serializable {
+public interface FileItem extends Serializable {
 
 
     // ------------------------------- Methods from javax.activation.DataSource
@@ -66,8 +65,7 @@
      *
      * @throws IOException if an error occurs.
      */
-    InputStream getInputStream()
-        throws IOException;
+    InputStream getInputStream() throws IOException;
 
 
     /**
@@ -132,8 +130,7 @@
      * @throws UnsupportedEncodingException if the requested character
      *                                      encoding is not available.
      */
-    String getString(String encoding)
-        throws UnsupportedEncodingException;
+    String getString(String encoding) throws UnsupportedEncodingException;
 
 
     /**

Modified: commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileItemHeaders.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileItemHeaders.java?rev=578253&r1=578252&r2=578253&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileItemHeaders.java
(original)
+++ commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileItemHeaders.java
Fri Sep 21 13:13:14 2007
@@ -16,7 +16,6 @@
  */
 package org.apache.commons.fileupload;
 
-import java.io.Serializable;
 import java.util.Iterator;
 
 /**
@@ -27,7 +26,7 @@
  * @author Michael C. Macaluso
  * @since 1.3
  */
-public interface FileItemHeaders extends Serializable {
+public interface FileItemHeaders {
     /**
      * Returns the value of the specified part header as a <code>String</code>.
      * If the part did not include a header of the specified name, this method

Modified: commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ParameterParser.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ParameterParser.java?rev=578253&r1=578252&r2=578253&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ParameterParser.java
(original)
+++ commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ParameterParser.java
Fri Sep 21 13:13:14 2007
@@ -220,7 +220,7 @@
      * the earliest found in the input string is used.
      *
      * @param str the string that contains a sequence of name/value pairs
-     * @param separator the name/value pairs separators
+     * @param separators the name/value pairs separators
      *
      * @return a map of name/value pairs
      */

Modified: commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/disk/DiskFileItem.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/disk/DiskFileItem.java?rev=578253&r1=578252&r2=578253&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/disk/DiskFileItem.java
(original)
+++ commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/disk/DiskFileItem.java
Fri Sep 21 13:13:14 2007
@@ -24,22 +24,20 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.ObjectOutputStream;
 import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.Map;
 
-import org.apache.commons.io.FileCleaningTracker;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.FileCleaner;
-import org.apache.commons.io.output.DeferredFileOutputStream;
-
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.fileupload.FileItemHeaders;
 import org.apache.commons.fileupload.FileItemHeadersSupport;
 import org.apache.commons.fileupload.FileUploadException;
 import org.apache.commons.fileupload.ParameterParser;
+import org.apache.commons.io.FileCleaner;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.DeferredFileOutputStream;
 
 
 /**
@@ -168,14 +166,14 @@
     private transient DeferredFileOutputStream dfos;
 
     /**
-     * File to allow for serialization of the content of this item.
+     * The temporary file to use.
      */
-    private File dfosFile;
+    private File tempFile;
 
     /**
-     * The tracker, which is responsible for deleting the temporary file.
+     * File to allow for serialization of the content of this item.
      */
-    private FileCleaningTracker fileCleaningTracker;
+    private File dfosFile;
 
     /**
      * The file items headers.
@@ -201,41 +199,10 @@
      * @param repository    The data repository, which is the directory in
      *                      which files will be created, should the item size
      *                      exceed the threshold.
-     * @deprecated Use {@link #DiskFileItem(FileCleaningTracker, String, String,
-     *                                      boolean, String, int, File)}.
      */
-    public DiskFileItem(String fieldName, String contentType,
-            boolean isFormField, String fileName, int sizeThreshold,
-            File repository) {
-        this(FileCleaner.getInstance(), fieldName, contentType,
-                isFormField, fileName, sizeThreshold,
-                repository);
-    }
-
-    /**
-     * Constructs a new <code>DiskFileItem</code> instance.
-     *
-     * @param tracker       The tracker, which is responsible for deleting
-     *                      the temporary file. May be null, if the file
-     *                      doesn't need to be tracked.
-     * @param fieldName     The name of the form field.
-     * @param contentType   The content type passed by the browser or
-     *                      <code>null</code> if not specified.
-     * @param isFormField   Whether or not this item is a plain form field, as
-     *                      opposed to a file upload.
-     * @param fileName      The original filename in the user's filesystem, or
-     *                      <code>null</code> if not specified.
-     * @param sizeThreshold The threshold, in bytes, below which items will be
-     *                      retained in memory and above which they will be
-     *                      stored as a file.
-     * @param repository    The data repository, which is the directory in
-     *                      which files will be created, should the item size
-     *                      exceed the threshold.
-     */
-    private DiskFileItem(FileCleaningTracker tracker, String fieldName,
+    public DiskFileItem(String fieldName,
             String contentType, boolean isFormField, String fileName,
             int sizeThreshold, File repository) {
-        this.fileCleaningTracker = tracker;
         this.fieldName = fieldName;
         this.contentType = contentType;
         this.isFormField = isFormField;
@@ -244,25 +211,6 @@
         this.repository = repository;
     }
 
-    /**
-     * Constructs a new <code>DiskFileItem</code> instance.
-     *
-     * @param factory       The factory, which is creating this instance.
-     * @param fieldName     The name of the form field.
-     * @param contentType   The content type passed by the browser or
-     *                      <code>null</code> if not specified.
-     * @param isFormField   Whether or not this item is a plain form field, as
-     *                      opposed to a file upload.
-     * @param fileName      The original filename in the user's filesystem, or
-     *                      <code>null</code> if not specified.
-     */
-    public DiskFileItem(DiskFileItemFactory factory, String fieldName,
-            String contentType, boolean isFormField, String fileName) {
-        this(factory.getFileCleaningTracker(), fieldName, contentType,
-                isFormField, fileName, factory.getSizeThreshold(),
-                factory.getRepository());
-    }
-
 
     // ------------------------------- Methods from javax.activation.DataSource
 
@@ -649,30 +597,25 @@
 
 
     /**
-     * <p>Creates and returns a {@link java.io.File File} representing a uniquely
-     * named temporary file in the configured repository path.</p>
-     * <p>If the file item factory has an associated {@link FileCleaningTracker},
-     * then the lifetime of the file is tied to the lifetime of the <code>FileItem</code>
-     * instance: The file will be deleted when the instance is garbage collected.</p>
+     * Creates and returns a {@link java.io.File File} representing a uniquely
+     * named temporary file in the configured repository path. The lifetime of
+     * the file is tied to the lifetime of the <code>FileItem</code> instance;
+     * the file will be deleted when the instance is garbage collected.
      *
      * @return The {@link java.io.File File} to be used for temporary storage.
      */
     protected File getTempFile() {
-        File tempDir = repository;
-        if (tempDir == null) {
-            tempDir = new File(System.getProperty("java.io.tmpdir"));
-        }
-
-        String tempFileName = "upload_" + UID + "_" + getUniqueId() + ".tmp";
-
-        File f = new File(tempDir, tempFileName);
-        if (fileCleaningTracker != null) {
-            /* If a tracker is present, use it. Otherwise, we've got to trust
-             * in the {@link #finalize()} method.
-             */
-            fileCleaningTracker.track(f, this);
+        if (tempFile == null) {
+            File tempDir = repository;
+            if (tempDir == null) {
+                tempDir = new File(System.getProperty("java.io.tmpdir"));
+            }
+    
+            String tempFileName = "upload_" + UID + "_" + getUniqueId() + ".tmp";
+    
+            tempFile = new File(tempDir, tempFileName);
         }
-        return f;
+        return tempFile;
     }
 
 

Modified: commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/disk/DiskFileItemFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/disk/DiskFileItemFactory.java?rev=578253&r1=578252&r2=578253&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/disk/DiskFileItemFactory.java
(original)
+++ commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/disk/DiskFileItemFactory.java
Fri Sep 21 13:13:14 2007
@@ -97,11 +97,9 @@
     /**
      * Constructs an unconfigured instance of this class. The resulting factory
      * may be configured by calling the appropriate setter methods.
-     * @deprecated Use
-     *     {@link #DiskFileItemFactory(FileCleaningTracker, int, File)}.
      */
     public DiskFileItemFactory() {
-        this(FileCleaner.getInstance(), DEFAULT_SIZE_THRESHOLD, null);
+        this(DEFAULT_SIZE_THRESHOLD, null);
     }
 
 
@@ -114,31 +112,10 @@
      * @param repository    The data repository, which is the directory in
      *                      which files will be created, should the item size
      *                      exceed the threshold.
-     * @deprecated Use
-     *     {@link #DiskFileItemFactory(FileCleaningTracker, int, File)}.
      */
     public DiskFileItemFactory(int sizeThreshold, File repository) {
-        this(FileCleaner.getInstance(), sizeThreshold, repository);
-    }
-
-    /**
-     * Constructs a preconfigured instance of this class.
-     *
-     * @param sizeThreshold The threshold, in bytes, below which items will be
-     *                      retained in memory and above which they will be
-     *                      stored as a file.
-     * @param repository    The data repository, which is the directory in
-     *                      which files will be created, should the item size
-     *                      exceed the threshold.
-     * @param tracker       The tracker, which is responsible to delete
-     *                      temporary files. May be null, if files don't need
-     *                      to be tracked.
-     */
-    public DiskFileItemFactory(FileCleaningTracker tracker, int sizeThreshold,
-            File repository) {
         this.sizeThreshold = sizeThreshold;
         this.repository = repository;
-        this.fileCleaningTracker = tracker;
     }
 
     // ------------------------------------------------------------- Properties
@@ -214,16 +191,18 @@
      *
      * @return The newly created file item.
      */
-    public FileItem createItem(
-            String fieldName,
-            String contentType,
-            boolean isFormField,
-            String fileName
-            ) {
-        return new DiskFileItem(this, fieldName, contentType,
-                isFormField, fileName);
+    public FileItem createItem(String fieldName, String contentType,
+            boolean isFormField, String fileName) {
+        DiskFileItem result = new DiskFileItem(fieldName, contentType,
+                isFormField, fileName, sizeThreshold, repository);
+        FileCleaningTracker tracker = getFileCleaningTracker();
+        if (tracker != null) {
+            tracker.track(result.getTempFile(), this);
+        }
+        return result;
     }
 
+
     /**
      * Returns the tracker, which is responsible for deleting temporary
      * files.
@@ -245,5 +224,4 @@
     public void setFileCleaningTracker(FileCleaningTracker pTracker) {
         fileCleaningTracker = pTracker;
     }
-
 }

Modified: commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/servlet/FileCleanerCleanup.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/servlet/FileCleanerCleanup.java?rev=578253&r1=578252&r2=578253&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/servlet/FileCleanerCleanup.java
(original)
+++ commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/servlet/FileCleanerCleanup.java
Fri Sep 21 13:13:14 2007
@@ -20,6 +20,7 @@
 import javax.servlet.ServletContextListener;
 import javax.servlet.ServletContextEvent;
 
+import org.apache.commons.io.FileCleaner;
 import org.apache.commons.io.FileCleaningTracker;
 
 

Modified: commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/util/FileItemHeadersImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/util/FileItemHeadersImpl.java?rev=578253&r1=578252&r2=578253&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/util/FileItemHeadersImpl.java
(original)
+++ commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/util/FileItemHeadersImpl.java
Fri Sep 21 13:13:14 2007
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.fileupload.util;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -31,7 +32,7 @@
  * @author Michael C. Macaluso
  * @since 1.3
  */
-public class FileItemHeadersImpl implements FileItemHeaders {
+public class FileItemHeadersImpl implements FileItemHeaders, Serializable {
     private static final long serialVersionUID = -4455695752627032559L;
 
     /**

Modified: commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/DiskFileItemSerializeTest.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/DiskFileItemSerializeTest.java?rev=578253&r1=578252&r2=578253&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/DiskFileItemSerializeTest.java
(original)
+++ commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/DiskFileItemSerializeTest.java
Fri Sep 21 13:13:14 2007
@@ -16,17 +16,14 @@
  */
 package org.apache.commons.fileupload;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.util.Arrays;
 
 import junit.framework.TestCase;
-import org.apache.commons.fileupload.disk.DiskFileItem;
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 
 

Modified: commons/proper/fileupload/trunk/xdocs/using.xml
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/xdocs/using.xml?rev=578253&r1=578252&r2=578253&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/xdocs/using.xml (original)
+++ commons/proper/fileupload/trunk/xdocs/using.xml Fri Sep 21 13:13:14 2007
@@ -283,23 +283,15 @@
     <p>
       Such temporary files are deleted automatically, if they are no longer
       used (more precisely, if the corresponding instance of <code>java.io.File</code>
-      is garbage collected. This is done silently by an instance of
-      <code>org.apache.commons.io.FileCleaningTracker</code>, which starts a
-      reaper thread.
+      is garbage collected. This is done silently by the <code>org.apache.commons.io.FileCleaner</code>
+      class, which starts a reaper thread.
     </p>
     <p>
-      In what follows, we assume that you are writing a web application. In
-      a web application, resource cleanup is controlled by an instance of
-      <code>javax.servlet.ServletContextListener</code>. In other environments,
-      similar ideas must be applied.
-    </p>
-
-    <subsection name="The FileCleanerCleanup">
-      <p>
-        Your web application should use an instance of
-        <code>org.apache.commons.fileupload.FileCleanerCleanup</code>.
-        That's very easy, you've simply got to add it to your <code>web.xml</code>:
-      </p>
+      This reaper thread should be stopped, if it is no longer needed. In
+      a servlet environment, this is done by using a special servlet
+      context listener, called
+      <a href="apidocs/org/apache/commons/fileupload/servlet/FileCleanerCleanup.html">FileCleanerCleanup</a>.
+      To do so, add a section like the following to your <code>web.xml</code>:
 <source><![CDATA[
 <web-app>
   ...



Mime
View raw message