Package com.helger.web.fileupload.parse
Class DiskFileItemFactory
- java.lang.Object
-
- com.helger.web.fileupload.parse.DiskFileItemFactory
-
- All Implemented Interfaces:
IFileItemFactory
@ThreadSafe public class DiskFileItemFactory extends Object implements IFileItemFactory
The default
IFileItemFactoryimplementation. This implementation createsDiskFileIteminstances 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").
Temporary files, which are created for file items, should be deleted later on.
- Author:
- Martin Cooper, Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description protected com.helger.commons.concurrent.SimpleReadWriteLockm_aRWLock
-
Constructor Summary
Constructors Constructor Description DiskFileItemFactory(int nSizeThreshold)DiskFileItemFactory(int nSizeThreshold, File aRepository)Constructs a preconfigured instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DiskFileItemcreateItem(String sFieldName, String sContentType, boolean bIsFormField, String sFileName)Create a newDiskFileIteminstance from the supplied parameters and the local factory configuration.voiddeleteAllTemporaryFiles()com.helger.commons.collection.impl.ICommonsList<File>getAllTemporaryFiles()voidsetRepository(File aRepository)Define where to store files
-
-
-
Constructor Detail
-
DiskFileItemFactory
@VisibleForTesting public DiskFileItemFactory(@Nonnegative int nSizeThreshold)
-
DiskFileItemFactory
public DiskFileItemFactory(@Nonnegative int nSizeThreshold, @Nullable File aRepository)
Constructs a preconfigured instance of this class.- Parameters:
nSizeThreshold- The threshold, in bytes, below which items will be retained in memory and above which they will be stored as a file.aRepository- The data repository, which is the directory in which files will be created, should the item size exceed the threshold.
-
-
Method Detail
-
setRepository
public void setRepository(@Nullable File aRepository)
Description copied from interface:IFileItemFactoryDefine where to store files- Specified by:
setRepositoryin interfaceIFileItemFactory- Parameters:
aRepository- The directory to use. May benull.
-
createItem
@Nonnull public DiskFileItem createItem(@Nullable String sFieldName, @Nullable String sContentType, boolean bIsFormField, @Nullable String sFileName)
Create a newDiskFileIteminstance from the supplied parameters and the local factory configuration.- Specified by:
createItemin interfaceIFileItemFactory- Parameters:
sFieldName- The name of the form field.sContentType- The content type of the form field.bIsFormField-trueif this is a plain form field;falseotherwise.sFileName- The name of the uploaded file, if any, as supplied by the browser or other client.- Returns:
- The newly created file item.
-
getAllTemporaryFiles
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<File> getAllTemporaryFiles()
- Specified by:
getAllTemporaryFilesin interfaceIFileItemFactory
-
deleteAllTemporaryFiles
public void deleteAllTemporaryFiles()
-
-