1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.fileupload;
17
18 import java.io.File;
19 import java.util.List;
20 import javax.servlet.http.HttpServletRequest;
21
22 /***
23 * <p>High level API for processing file uploads.</p>
24 *
25 * <p>This class handles multiple files per single HTML widget, sent using
26 * <code>multipart/mixed</code> encoding type, as specified by
27 * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>. Use {@link
28 * #parseRequest(HttpServletRequest)} to acquire a list of {@link
29 * org.apache.commons.fileupload.FileItem}s associated with a given HTML
30 * widget.</p>
31 *
32 * <p>Individual parts will be stored in temporary disk storage or in memory,
33 * depending on their size, and will be available as {@link
34 * org.apache.commons.fileupload.FileItem}s.</p>
35 *
36 * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
37 * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
38 * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
39 * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
40 * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
41 * @author Sean C. Sullivan
42 *
43 * @version $Id: DiskFileUpload.java 349366 2005-11-28 04:44:57Z martinc $
44 *
45 * @deprecated Use <code>ServletFileUpload</code> together with
46 * <code>DiskFileItemFactory</code> instead.
47 */
48 public class DiskFileUpload
49 extends FileUploadBase {
50
51
52
53
54 /***
55 * The factory to use to create new form items.
56 */
57 private DefaultFileItemFactory fileItemFactory;
58
59
60
61
62
63 /***
64 * Constructs an instance of this class which uses the default factory to
65 * create <code>FileItem</code> instances.
66 *
67 * @see #DiskFileUpload(DefaultFileItemFactory fileItemFactory)
68 *
69 * @deprecated Use <code>FileUpload</code> instead.
70 */
71 public DiskFileUpload() {
72 super();
73 this.fileItemFactory = new DefaultFileItemFactory();
74 }
75
76
77 /***
78 * Constructs an instance of this class which uses the supplied factory to
79 * create <code>FileItem</code> instances.
80 *
81 * @see #DiskFileUpload()
82 *
83 * @deprecated Use <code>FileUpload</code> instead.
84 */
85 public DiskFileUpload(DefaultFileItemFactory fileItemFactory) {
86 super();
87 this.fileItemFactory = fileItemFactory;
88 }
89
90
91
92
93
94 /***
95 * Returns the factory class used when creating file items.
96 *
97 * @return The factory class for new file items.
98 *
99 * @deprecated Use <code>FileUpload</code> instead.
100 */
101 public FileItemFactory getFileItemFactory() {
102 return fileItemFactory;
103 }
104
105
106 /***
107 * Sets the factory class to use when creating file items. The factory must
108 * be an instance of <code>DefaultFileItemFactory</code> or a subclass
109 * thereof, or else a <code>ClassCastException</code> will be thrown.
110 *
111 * @param factory The factory class for new file items.
112 *
113 * @deprecated Use <code>FileUpload</code> instead.
114 */
115 public void setFileItemFactory(FileItemFactory factory) {
116 this.fileItemFactory = (DefaultFileItemFactory) factory;
117 }
118
119
120 /***
121 * Returns the size threshold beyond which files are written directly to
122 * disk.
123 *
124 * @return The size threshold, in bytes.
125 *
126 * @see #setSizeThreshold(int)
127 *
128 * @deprecated Use <code>DiskFileItemFactory</code> instead.
129 */
130 public int getSizeThreshold() {
131 return fileItemFactory.getSizeThreshold();
132 }
133
134
135 /***
136 * Sets the size threshold beyond which files are written directly to disk.
137 *
138 * @param sizeThreshold The size threshold, in bytes.
139 *
140 * @see #getSizeThreshold()
141 *
142 * @deprecated Use <code>DiskFileItemFactory</code> instead.
143 */
144 public void setSizeThreshold(int sizeThreshold) {
145 fileItemFactory.setSizeThreshold(sizeThreshold);
146 }
147
148
149 /***
150 * Returns the location used to temporarily store files that are larger
151 * than the configured size threshold.
152 *
153 * @return The path to the temporary file location.
154 *
155 * @see #setRepositoryPath(String)
156 *
157 * @deprecated Use <code>DiskFileItemFactory</code> instead.
158 */
159 public String getRepositoryPath() {
160 return fileItemFactory.getRepository().getPath();
161 }
162
163
164 /***
165 * Sets the location used to temporarily store files that are larger
166 * than the configured size threshold.
167 *
168 * @param repositoryPath The path to the temporary file location.
169 *
170 * @see #getRepositoryPath()
171 *
172 * @deprecated Use <code>DiskFileItemFactory</code> instead.
173 */
174 public void setRepositoryPath(String repositoryPath) {
175 fileItemFactory.setRepository(new File(repositoryPath));
176 }
177
178
179
180
181
182 /***
183 * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
184 * compliant <code>multipart/form-data</code> stream. If files are stored
185 * on disk, the path is given by <code>getRepository()</code>.
186 *
187 * @param req The servlet request to be parsed. Must be non-null.
188 * @param sizeThreshold The max size in bytes to be stored in memory.
189 * @param sizeMax The maximum allowed upload size, in bytes.
190 * @param path The location where the files should be stored.
191 *
192 * @return A list of <code>FileItem</code> instances parsed from the
193 * request, in the order that they were transmitted.
194 *
195 * @throws FileUploadException if there are problems reading/parsing
196 * the request or storing files.
197 *
198 * @deprecated Use <code>ServletFileUpload</code> instead.
199 */
200 public List
201 int sizeThreshold,
202 long sizeMax, String path)
203 throws FileUploadException {
204 setSizeThreshold(sizeThreshold);
205 setSizeMax(sizeMax);
206 setRepositoryPath(path);
207 return parseRequest(req);
208 }
209
210 }