@ThreadSafe public class DiskFileItemFactory extends Object implements IFileItemFactory
The default IFileItemFactory
implementation. This implementation creates DiskFileItem 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:
System.getProperty("java.io.tmpdir").Temporary files, which are created for file items, should be deleted later on.
| Modifier and Type | Field and Description |
|---|---|
protected com.helger.commons.concurrent.SimpleReadWriteLock |
m_aRWLock |
| Constructor and Description |
|---|
DiskFileItemFactory(int nSizeThreshold) |
DiskFileItemFactory(int nSizeThreshold,
File aRepository)
Constructs a preconfigured instance of this class.
|
| Modifier and Type | Method and Description |
|---|---|
DiskFileItem |
createItem(String sFieldName,
String sContentType,
boolean bIsFormField,
String sFileName)
Create a new
DiskFileItem instance
from the supplied parameters and the local factory configuration. |
void |
deleteAllTemporaryFiles() |
com.helger.commons.collection.impl.ICommonsList<File> |
getAllTemporaryFiles() |
void |
setRepository(File aRepository)
Define where to store files
|
@VisibleForTesting public DiskFileItemFactory(@Nonnegative int nSizeThreshold)
public DiskFileItemFactory(@Nonnegative int nSizeThreshold, @Nullable File aRepository)
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.public void setRepository(@Nullable File aRepository)
IFileItemFactorysetRepository in interface IFileItemFactoryaRepository - The directory to use. May be null.@Nonnull public DiskFileItem createItem(@Nullable String sFieldName, @Nullable String sContentType, boolean bIsFormField, @Nullable String sFileName)
DiskFileItem instance
from the supplied parameters and the local factory configuration.createItem in interface IFileItemFactorysFieldName - The name of the form field.sContentType - The content type of the form field.bIsFormField - true if this is a plain form field; false
otherwise.sFileName - The name of the uploaded file, if any, as supplied by the browser or
other client.@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<File> getAllTemporaryFiles()
getAllTemporaryFiles in interface IFileItemFactorypublic void deleteAllTemporaryFiles()
Copyright © 2014–2019 Philip Helger. All rights reserved.