Class DiskFileItemFactory

  • All Implemented Interfaces:
    IFileItemFactory

    @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:

    • 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 Detail

      • m_aRWLock

        protected final com.helger.commons.concurrent.SimpleReadWriteLock m_aRWLock
    • 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

      • createItem

        @Nonnull
        public DiskFileItem createItem​(@Nullable
                                       String sFieldName,
                                       @Nullable
                                       String sContentType,
                                       boolean bIsFormField,
                                       @Nullable
                                       String sFileName)
        Create a new DiskFileItem instance from the supplied parameters and the local factory configuration.
        Specified by:
        createItem in interface IFileItemFactory
        Parameters:
        sFieldName - 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.
        Returns:
        The newly created file item.
      • deleteAllTemporaryFiles

        public void deleteAllTemporaryFiles()