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