org.apache.commons.fileupload

Class DefaultFileItemFactory

Implemented Interfaces:
FileItemFactory

public class DefaultFileItemFactory
extends java.lang.Object
implements FileItemFactory

The default FileItemFactory implementation. This implementation creates 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:

Version:
$Id: DefaultFileItemFactory.java,v 1.2 2003/05/31 22:31:08 martinc Exp $

Author:
Martin Cooper

Field Summary

static 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.

Constructor Summary

DefaultFileItemFactory()
Constructs an unconfigured instance of this class.
DefaultFileItemFactory(int sizeThreshold, File repository)
Constructs a preconfigured instance of this class.

Method Summary

FileItem
createItem(String fieldName, String contentType, boolean isFormField, String fileName)
Create a new DefaultFileItem instance from the supplied parameters and the local factory configuration.
File
getRepository()
Returns the directory used to temporarily store files that are larger than the configured size threshold.
int
getSizeThreshold()
Returns the size threshold beyond which files are written directly to disk.
void
setRepository(File repository)
Sets the directory used to temporarily store files that are larger than the configured size threshold.
void
setSizeThreshold(int sizeThreshold)
Sets the size threshold beyond which files are written directly to disk.

Field Details

DEFAULT_SIZE_THRESHOLD

public static final int DEFAULT_SIZE_THRESHOLD
The default threshold above which uploads will be stored on disk.

Field Value:
10240


repository

private File repository
The directory in which uploaded files will be stored, if stored on disk.


sizeThreshold

private int sizeThreshold
The threshold above which uploads will be stored on disk.

Constructor Details

DefaultFileItemFactory

public DefaultFileItemFactory()
Constructs an unconfigured instance of this class. The resulting factory may be configured by calling the appropriate setter methods.


DefaultFileItemFactory

public DefaultFileItemFactory(int sizeThreshold,
                              File repository)
Constructs a preconfigured instance of this class.

Parameters:
sizeThreshold - The threshold, in bytes, below which items will be retained in memory and above which they will be stored as a file.
repository - The data repository, which is the directory in which files will be created, should the item size exceed the threshold.

Method Details

createItem

public FileItem createItem(String fieldName,
                           String contentType,
                           boolean isFormField,
                           String fileName)
Create a new DefaultFileItem instance from the supplied parameters and the local factory configuration.
Specified by:
createItem in interface FileItemFactory

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

Returns:
The newly created file item.


getRepository

public File getRepository()
Returns the directory used to temporarily store files that are larger than the configured size threshold.

Returns:
The directory in which temporary files will be located.

See Also:
setRepository(java.io.File)


getSizeThreshold

public int getSizeThreshold()
Returns the size threshold beyond which files are written directly to disk. The default value is 1024 bytes.

Returns:
The size threshold, in bytes.

See Also:
setSizeThreshold(int)


setRepository

public void setRepository(File repository)
Sets the directory used to temporarily store files that are larger than the configured size threshold.

Parameters:
repository - The directory in which temporary files will be located.

See Also:
getRepository()


setSizeThreshold

public void setSizeThreshold(int sizeThreshold)
Sets the size threshold beyond which files are written directly to disk.

Parameters:
sizeThreshold - The size threshold, in bytes.

See Also:
getSizeThreshold()


Copyright © 2002-2003 Apache Software Foundation. All Rights Reserved.