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

DefaultFileItemFactory

public class DefaultFileItemFactory extends Object implements FileItemFactory

The default {@link org.apache.tomcat.util.http.fileupload.FileItemFactory} implementation. This implementation creates {@link org.apache.tomcat.util.http.fileupload.FileItem} instances which keep their content either in memory, for smaller items, or in a temporary file on disk, for larger items. The size threshold, above which content will be stored on disk, is configurable, as is the directory in which temporary files will be created.

If not otherwise configured, the default configuration values are as follows:

  • Size threshold is 10KB.
  • Repository is the system default temp directory, as returned by System.getProperty("java.io.tmpdir").

author
Martin Cooper
version
$Id: DefaultFileItemFactory.java 467222 2006-10-24 03:17:11Z markt $

Fields Summary
public static final int
DEFAULT_SIZE_THRESHOLD
The default threshold above which uploads will be stored on disk.
private File
repository
The directory in which uploaded files will be stored, if stored on disk.
private int
sizeThreshold
The threshold above which uploads will be stored on disk.
Constructors Summary
public DefaultFileItemFactory()
Constructs an unconfigured instance of this class. The resulting factory may be configured by calling the appropriate setter methods.



    // ----------------------------------------------------------- Constructors


                            
     
    
    
public DefaultFileItemFactory(int sizeThreshold, File 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.

        this.sizeThreshold = sizeThreshold;
        this.repository = repository;
    
Methods Summary
public FileItemcreateItem(java.lang.String fieldName, java.lang.String contentType, boolean isFormField, java.lang.String fileName)
Create a new {@link org.apache.tomcat.util.http.fileupload.DefaultFileItem} instance from the supplied parameters and the local factory configuration.

param
fieldName The name of the form field.
param
contentType The content type of the form field.
param
isFormField true if this is a plain form field; false otherwise.
param
fileName The name of the uploaded file, if any, as supplied by the browser or other client.
return
The newly created file item.

        return new DefaultFileItem(fieldName, contentType,
                isFormField, fileName, sizeThreshold, repository);
    
public java.io.FilegetRepository()
Returns the directory used to temporarily store files that are larger than the configured size threshold.

return
The directory in which temporary files will be located.
see
#setRepository(java.io.File)

        return repository;
    
public intgetSizeThreshold()
Returns the size threshold beyond which files are written directly to disk. The default value is 1024 bytes.

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

        return sizeThreshold;
    
public voidsetRepository(java.io.File repository)
Sets the directory used to temporarily store files that are larger than the configured size threshold.

param
repository The directory in which temporary files will be located.
see
#getRepository()

        this.repository = repository;
    
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()

        this.sizeThreshold = sizeThreshold;