Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use FileCleanerCleanup and FileCleaningTracker

843841Oct 21 2007 — edited Oct 31 2007
Hi.
I was hoping someone could help with some example code.
I am using the org.apache.commons.fileupload and other associated packages to upload files in a tomcat web server. All works fine, except I'm not sure how to use the components for file cleanup. You would typically upload a file to a temporary location. When it has finished, the file is copied to its permanent location and the temp file is "cleaned up" or deleted later on. The documentation from the website:

http://commons.apache.org/fileupload/using.html

has the following example code:
public static DiskFileItemFactory newDiskFileItemFactory(ServletContext context,
                                                             File repository) {
        FileCleaningTracker fileCleaningTracker
            = FileCleanerCleanup.getFileCleaningTracker(context);
        return new DiskFileItemFactory(fileCleaningTracker,
                                       DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD,
                                       repository);
    }
However, I had found that this example does not reflect the FileCleanerCleanup class (no accessor or mutators on the FileCleaningTracker). The following link describes the discrepancy:

http://www.nabble.com/-jira--Created:-(FILEUPLOAD-147)-Incorrect-Information-in-documentation.-t4550577.html

Now the following javadoc matches the example code above:

http://people.apache.org/~jochen/commons-fileupload/site/apidocs/org/apache/commons/fileupload2/servlet/FileCleanerCleanup.html

If anyone knows were to get the org.apache.commons.fileupload2.servlet package (note the "2"), for download, that would help a lot.
Otherwise I'd be interested in any example code that demonstrates how to cleanup those temp files using the standard fileupload and associated packages:

org.apache.commons.fileupload
org.apache.commons.fileupload.disk
org.apache.commons.fileupload.servlet
org.apache.commons.io (for the FileCleaningTracker).
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 28 2007
Added on Oct 21 2007
2 comments
1,874 views