您的位置:首页 > 运维架构 > Apache

org.apache.commons.fileupload.disk.DiskFileItemFactory

2011-10-24 10:34 471 查看
public class DiskFileItemFactoryextends java.lang.Objectimplements 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:

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

When using the
DiskFileItemFactory
, then you should consider the following: Temporary files are automatically deleted as soon as they are no longer needed. (More precisely, when the corresponding instance of
File
is garbage collected.) Cleaning up those files is done by an instance of
FileCleaningTracker
, and an associated thread. In a complex environment, for example in a web application, you should consider terminating this thread, for example, when your web application ends. See the section on "Resource cleanup" in the users
guide of commons-fileupload.

FileItemFactory
的默认实现类。这个实现类负责创建
FileItem
的实例,使得
FileItem
对应的文件的内容既可以保存在内存中(小文件)又可以作为临时文件保存到硬盘中(大文件)。到底多大的文件才算大文件,临时文件到底存放到硬盘中的什么目录下,都是可以通过设置来指定的。

如果没有设置,那么默认值如下所示:

。大小界限:10KB

。文件存放位置是系统的默认临时文件的存放文件夹,这个具体的值可以通过
System.getProperty("java.io.tmpdir")
. 获得

在使用
DiskFileItemFactory
的时候,有些地方你需要注意的是:临时文件在不再使用的情况下(更准确地说,就是当File实例被回收机制回收的时候),会由系统自动删除的。[code]FileCleaningTracker负责清除这些文件以及与这些文件有关的进程。在复杂的环境下,例如在web应用中,你应该考虑关掉
FileCleaningTracker
的进程。对于这一点,你可以考虑参考commons-fileupload的用户手册关于"Resource
cleanup"一章。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐