FileDocCategorySizeDatePackage
DiskFileUpload.javaAPI DocApache Tomcat 6.0.146674Fri Jul 20 04:20:32 BST 2007org.apache.tomcat.util.http.fileupload

DiskFileUpload

public class DiskFileUpload extends FileUploadBase

High level API for processing file uploads.

This class handles multiple files per single HTML widget, sent using multipart/mixed encoding type, as specified by RFC 1867. Use {@link #parseRequest(HttpServletRequest)} to acquire a list of {@link org.apache.tomcat.util.http.fileupload.FileItem}s associated with a given HTML widget.

Individual parts will be stored in temporary disk storage or in memory, depending on their size, and will be available as {@link org.apache.tomcat.util.http.fileupload.FileItem}s.

author
Rafal Krzewski
author
Daniel Rall
author
Jason van Zyl
author
John McNally
author
Martin Cooper
author
Sean C. Sullivan
version
$Id: DiskFileUpload.java 467222 2006-10-24 03:17:11Z markt $

Fields Summary
private DefaultFileItemFactory
fileItemFactory
The factory to use to create new form items.
Constructors Summary
public DiskFileUpload()
Constructs an instance of this class which uses the default factory to create FileItem instances.

see
#DiskFileUpload(DefaultFileItemFactory fileItemFactory)

        super();
        this.fileItemFactory = new DefaultFileItemFactory();
    
public DiskFileUpload(DefaultFileItemFactory fileItemFactory)
Constructs an instance of this class which uses the supplied factory to create FileItem instances.

see
#DiskFileUpload()

        super();
        this.fileItemFactory = fileItemFactory;
    
Methods Summary
public FileItemFactorygetFileItemFactory()
Returns the factory class used when creating file items.

return
The factory class for new file items.

        return fileItemFactory;
    
public java.lang.StringgetRepositoryPath()
Returns the location used to temporarily store files that are larger than the configured size threshold.

return
The path to the temporary file location.
see
#setRepositoryPath(String)

        return fileItemFactory.getRepository().getPath();
    
public intgetSizeThreshold()
Returns the size threshold beyond which files are written directly to disk.

return
The size threshold, in bytes.
see
#setSizeThreshold(int)

        return fileItemFactory.getSizeThreshold();
    
public java.util.ListparseRequest(javax.servlet.http.HttpServletRequest req, int sizeThreshold, long sizeMax, java.lang.String path)
Processes an RFC 1867 compliant multipart/form-data stream. If files are stored on disk, the path is given by getRepository().

param
req The servlet request to be parsed. Must be non-null.
param
sizeThreshold The max size in bytes to be stored in memory.
param
sizeMax The maximum allowed upload size, in bytes.
param
path The location where the files should be stored.
return
A list of FileItem instances parsed from the request, in the order that they were transmitted.
exception
FileUploadException if there are problems reading/parsing the request or storing files.

        setSizeThreshold(sizeThreshold);
        setSizeMax(sizeMax);
        setRepositoryPath(path);
        return parseRequest(req);
    
public voidsetFileItemFactory(FileItemFactory factory)
Sets the factory class to use when creating file items. The factory must be an instance of DefaultFileItemFactory or a subclass thereof, or else a ClassCastException will be thrown.

param
factory The factory class for new file items.

        this.fileItemFactory = (DefaultFileItemFactory) factory;
    
public voidsetRepositoryPath(java.lang.String repositoryPath)
Sets the location used to temporarily store files that are larger than the configured size threshold.

param
repositoryPath The path to the temporary file location.
see
#getRepositoryPath()

        fileItemFactory.setRepository(new File(repositoryPath));
    
public voidsetSizeThreshold(int sizeThreshold)
Sets the size threshold beyond which files are written directly to disk.

param
sizeThreshold The size threshold, in bytes.
see
#getSizeThreshold()

        fileItemFactory.setSizeThreshold(sizeThreshold);