Source Code Cross Referenced for DiskFileItemFactory.java in  » Net » apache-common-FileUpload » org » apache » commons » fileupload » disk » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » apache common FileUpload » org.apache.commons.fileupload.disk 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.fileupload.disk;
018:
019:        import java.io.File;
020:
021:        import org.apache.commons.fileupload.FileItem;
022:        import org.apache.commons.fileupload.FileItemFactory;
023:
024:        /**
025:         * <p>The default {@link org.apache.commons.fileupload.FileItemFactory}
026:         * implementation. This implementation creates
027:         * {@link org.apache.commons.fileupload.FileItem} instances which keep their
028:         * content either in memory, for smaller items, or in a temporary file on disk,
029:         * for larger items. The size threshold, above which content will be stored on
030:         * disk, is configurable, as is the directory in which temporary files will be
031:         * created.</p>
032:         *
033:         * <p>If not otherwise configured, the default configuration values are as
034:         * follows:
035:         * <ul>
036:         *   <li>Size threshold is 10KB.</li>
037:         *   <li>Repository is the system default temp directory, as returned by
038:         *       <code>System.getProperty("java.io.tmpdir")</code>.</li>
039:         * </ul>
040:         * </p>
041:         *
042:         * <p>When using the <code>DiskFileItemFactory</code>, then you should
043:         * consider the following: Temporary files are automatically deleted as
044:         * soon as they are no longer needed. (More precisely, when the
045:         * corresponding instance of {@link java.io.File} is garbage collected.)
046:         * This is done by the so-called reaper thread, which is started
047:         * automatically when the class {@link org.apache.commons.io.FileCleaner}
048:         * is loaded. It might make sense to terminate that thread, for example,
049:         * if your web application ends. See the section on "Resource cleanup"
050:         * in the users guide of commons-fileupload.</p>
051:         *
052:         * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
053:         *
054:         * @since FileUpload 1.1
055:         *
056:         * @version $Id: DiskFileItemFactory.java 502350 2007-02-01 20:42:48Z jochen $
057:         */
058:        public class DiskFileItemFactory implements  FileItemFactory {
059:
060:            // ----------------------------------------------------- Manifest constants
061:
062:            /**
063:             * The default threshold above which uploads will be stored on disk.
064:             */
065:            public static final int DEFAULT_SIZE_THRESHOLD = 10240;
066:
067:            // ----------------------------------------------------- Instance Variables
068:
069:            /**
070:             * The directory in which uploaded files will be stored, if stored on disk.
071:             */
072:            private File repository;
073:
074:            /**
075:             * The threshold above which uploads will be stored on disk.
076:             */
077:            private int sizeThreshold = DEFAULT_SIZE_THRESHOLD;
078:
079:            // ----------------------------------------------------------- Constructors
080:
081:            /**
082:             * Constructs an unconfigured instance of this class. The resulting factory
083:             * may be configured by calling the appropriate setter methods.
084:             */
085:            public DiskFileItemFactory() {
086:                // Does nothing.
087:            }
088:
089:            /**
090:             * Constructs a preconfigured instance of this class.
091:             *
092:             * @param sizeThreshold The threshold, in bytes, below which items will be
093:             *                      retained in memory and above which they will be
094:             *                      stored as a file.
095:             * @param repository    The data repository, which is the directory in
096:             *                      which files will be created, should the item size
097:             *                      exceed the threshold.
098:             */
099:            public DiskFileItemFactory(int sizeThreshold, File repository) {
100:                this .sizeThreshold = sizeThreshold;
101:                this .repository = repository;
102:            }
103:
104:            // ------------------------------------------------------------- Properties
105:
106:            /**
107:             * Returns the directory used to temporarily store files that are larger
108:             * than the configured size threshold.
109:             *
110:             * @return The directory in which temporary files will be located.
111:             *
112:             * @see #setRepository(java.io.File)
113:             *
114:             */
115:            public File getRepository() {
116:                return repository;
117:            }
118:
119:            /**
120:             * Sets the directory used to temporarily store files that are larger
121:             * than the configured size threshold.
122:             *
123:             * @param repository The directory in which temporary files will be located.
124:             *
125:             * @see #getRepository()
126:             *
127:             */
128:            public void setRepository(File repository) {
129:                this .repository = repository;
130:            }
131:
132:            /**
133:             * Returns the size threshold beyond which files are written directly to
134:             * disk. The default value is 10240 bytes.
135:             *
136:             * @return The size threshold, in bytes.
137:             *
138:             * @see #setSizeThreshold(int)
139:             */
140:            public int getSizeThreshold() {
141:                return sizeThreshold;
142:            }
143:
144:            /**
145:             * Sets the size threshold beyond which files are written directly to disk.
146:             *
147:             * @param sizeThreshold The size threshold, in bytes.
148:             *
149:             * @see #getSizeThreshold()
150:             *
151:             */
152:            public void setSizeThreshold(int sizeThreshold) {
153:                this .sizeThreshold = sizeThreshold;
154:            }
155:
156:            // --------------------------------------------------------- Public Methods
157:
158:            /**
159:             * Create a new {@link org.apache.commons.fileupload.disk.DiskFileItem}
160:             * instance from the supplied parameters and the local factory
161:             * configuration.
162:             *
163:             * @param fieldName   The name of the form field.
164:             * @param contentType The content type of the form field.
165:             * @param isFormField <code>true</code> if this is a plain form field;
166:             *                    <code>false</code> otherwise.
167:             * @param fileName    The name of the uploaded file, if any, as supplied
168:             *                    by the browser or other client.
169:             *
170:             * @return The newly created file item.
171:             */
172:            public FileItem createItem(String fieldName, String contentType,
173:                    boolean isFormField, String fileName) {
174:                return new DiskFileItem(fieldName, contentType, isFormField,
175:                        fileName, sizeThreshold, repository);
176:            }
177:
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.