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 static java.lang.String.format;
20
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.io.UnsupportedEncodingException;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.Locale;
29 import java.util.Map;
30 import java.util.NoSuchElementException;
31
32 import javax.servlet.http.HttpServletRequest;
33
34 import org.apache.commons.fileupload.MultipartStream.ItemInputStream;
35 import org.apache.commons.fileupload.servlet.ServletFileUpload;
36 import org.apache.commons.fileupload.servlet.ServletRequestContext;
37 import org.apache.commons.fileupload.util.Closeable;
38 import org.apache.commons.fileupload.util.FileItemHeadersImpl;
39 import org.apache.commons.fileupload.util.LimitedInputStream;
40 import org.apache.commons.fileupload.util.Streams;
41 import org.apache.commons.io.IOUtils;
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 public abstract class FileUploadBase {
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 public static final boolean isMultipartContent(RequestContext ctx) {
76 String contentType = ctx.getContentType();
77 if (contentType == null) {
78 return false;
79 }
80 if (contentType.toLowerCase(Locale.ENGLISH).startsWith(MULTIPART)) {
81 return true;
82 }
83 return false;
84 }
85
86
87
88
89
90
91
92
93
94
95
96
97 @Deprecated
98 public static boolean isMultipartContent(HttpServletRequest req) {
99 return ServletFileUpload.isMultipartContent(req);
100 }
101
102
103
104
105
106
107 public static final String CONTENT_TYPE = "Content-type";
108
109
110
111
112 public static final String CONTENT_DISPOSITION = "Content-disposition";
113
114
115
116
117 public static final String CONTENT_LENGTH = "Content-length";
118
119
120
121
122 public static final String FORM_DATA = "form-data";
123
124
125
126
127 public static final String ATTACHMENT = "attachment";
128
129
130
131
132 public static final String MULTIPART = "multipart/";
133
134
135
136
137 public static final String MULTIPART_FORM_DATA = "multipart/form-data";
138
139
140
141
142 public static final String MULTIPART_MIXED = "multipart/mixed";
143
144
145
146
147
148
149
150
151 @Deprecated
152 public static final int MAX_HEADER_SIZE = 1024;
153
154
155
156
157
158
159
160 private long sizeMax = -1;
161
162
163
164
165
166 private long fileSizeMax = -1;
167
168
169
170
171 private String headerEncoding;
172
173
174
175
176 private ProgressListener listener;
177
178
179
180
181
182
183
184
185 public abstract FileItemFactory getFileItemFactory();
186
187
188
189
190
191
192 public abstract void setFileItemFactory(FileItemFactory factory);
193
194
195
196
197
198
199
200
201
202
203
204 public long getSizeMax() {
205 return sizeMax;
206 }
207
208
209
210
211
212
213
214
215
216
217
218 public void setSizeMax(long sizeMax) {
219 this.sizeMax = sizeMax;
220 }
221
222
223
224
225
226
227
228
229 public long getFileSizeMax() {
230 return fileSizeMax;
231 }
232
233
234
235
236
237
238
239
240 public void setFileSizeMax(long fileSizeMax) {
241 this.fileSizeMax = fileSizeMax;
242 }
243
244
245
246
247
248
249
250
251
252 public String getHeaderEncoding() {
253 return headerEncoding;
254 }
255
256
257
258
259
260
261
262
263
264 public void setHeaderEncoding(String encoding) {
265 headerEncoding = encoding;
266 }
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284 @Deprecated
285 public List<FileItem> parseRequest(HttpServletRequest req)
286 throws FileUploadException {
287 return parseRequest(new ServletRequestContext(req));
288 }
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306 public FileItemIterator getItemIterator(RequestContext ctx)
307 throws FileUploadException, IOException {
308 try {
309 return new FileItemIteratorImpl(ctx);
310 } catch (FileUploadIOException e) {
311
312 throw (FileUploadException) e.getCause();
313 }
314 }
315
316
317
318
319
320
321
322
323
324
325
326
327
328 public List<FileItem> parseRequest(RequestContext ctx)
329 throws FileUploadException {
330 List<FileItem> items = new ArrayList<FileItem>();
331 boolean successful = false;
332 try {
333 FileItemIterator iter = getItemIterator(ctx);
334 FileItemFactory fac = getFileItemFactory();
335 if (fac == null) {
336 throw new NullPointerException("No FileItemFactory has been set.");
337 }
338 while (iter.hasNext()) {
339 final FileItemStream item = iter.next();
340
341 final String fileName = ((FileItemIteratorImpl.FileItemStreamImpl) item).name;
342 FileItem fileItem = fac.createItem(item.getFieldName(), item.getContentType(),
343 item.isFormField(), fileName);
344 items.add(fileItem);
345 try {
346 Streams.copy(item.openStream(), fileItem.getOutputStream(), true);
347 } catch (FileUploadIOException e) {
348 throw (FileUploadException) e.getCause();
349 } catch (IOException e) {
350 throw new IOFileUploadException(format("Processing of %s request failed. %s",
351 MULTIPART_FORM_DATA, e.getMessage()), e);
352 }
353 final FileItemHeaders fih = item.getHeaders();
354 fileItem.setHeaders(fih);
355 }
356 successful = true;
357 return items;
358 } catch (FileUploadIOException e) {
359 throw (FileUploadException) e.getCause();
360 } catch (IOException e) {
361 throw new FileUploadException(e.getMessage(), e);
362 } finally {
363 if (!successful) {
364 for (FileItem fileItem : items) {
365 try {
366 fileItem.delete();
367 } catch (Exception ignored) {
368
369 }
370 }
371 }
372 }
373 }
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388 public Map<String, List<FileItem>> parseParameterMap(RequestContext ctx)
389 throws FileUploadException {
390 final List<FileItem> items = parseRequest(ctx);
391 final Map<String, List<FileItem>> itemsMap = new HashMap<String, List<FileItem>>(items.size());
392
393 for (FileItem fileItem : items) {
394 String fieldName = fileItem.getFieldName();
395 List<FileItem> mappedItems = itemsMap.get(fieldName);
396
397 if (mappedItems == null) {
398 mappedItems = new ArrayList<FileItem>();
399 itemsMap.put(fieldName, mappedItems);
400 }
401
402 mappedItems.add(fileItem);
403 }
404
405 return itemsMap;
406 }
407
408
409
410
411
412
413
414
415
416
417
418 protected byte[] getBoundary(String contentType) {
419 ParameterParser parser = new ParameterParser();
420 parser.setLowerCaseNames(true);
421
422 Map<String, String> params = parser.parse(contentType, new char[] {';', ','});
423 String boundaryStr = params.get("boundary");
424
425 if (boundaryStr == null) {
426 return null;
427 }
428 byte[] boundary;
429 try {
430 boundary = boundaryStr.getBytes("ISO-8859-1");
431 } catch (UnsupportedEncodingException e) {
432 boundary = boundaryStr.getBytes();
433 }
434 return boundary;
435 }
436
437
438
439
440
441
442
443
444
445
446 @Deprecated
447 protected String getFileName(Map<String, String> headers) {
448 return getFileName(getHeader(headers, CONTENT_DISPOSITION));
449 }
450
451
452
453
454
455
456
457
458
459 protected String getFileName(FileItemHeaders headers) {
460 return getFileName(headers.getHeader(CONTENT_DISPOSITION));
461 }
462
463
464
465
466
467
468 private String getFileName(String pContentDisposition) {
469 String fileName = null;
470 if (pContentDisposition != null) {
471 String cdl = pContentDisposition.toLowerCase(Locale.ENGLISH);
472 if (cdl.startsWith(FORM_DATA) || cdl.startsWith(ATTACHMENT)) {
473 ParameterParser parser = new ParameterParser();
474 parser.setLowerCaseNames(true);
475
476 Map<String, String> params = parser.parse(pContentDisposition, ';');
477 if (params.containsKey("filename")) {
478 fileName = params.get("filename");
479 if (fileName != null) {
480 fileName = fileName.trim();
481 } else {
482
483
484
485 fileName = "";
486 }
487 }
488 }
489 }
490 return fileName;
491 }
492
493
494
495
496
497
498
499
500
501 protected String getFieldName(FileItemHeaders headers) {
502 return getFieldName(headers.getHeader(CONTENT_DISPOSITION));
503 }
504
505
506
507
508
509
510
511 private String getFieldName(String pContentDisposition) {
512 String fieldName = null;
513 if (pContentDisposition != null
514 && pContentDisposition.toLowerCase(Locale.ENGLISH).startsWith(FORM_DATA)) {
515 ParameterParser parser = new ParameterParser();
516 parser.setLowerCaseNames(true);
517
518 Map<String, String> params = parser.parse(pContentDisposition, ';');
519 fieldName = params.get("name");
520 if (fieldName != null) {
521 fieldName = fieldName.trim();
522 }
523 }
524 return fieldName;
525 }
526
527
528
529
530
531
532
533
534
535
536 @Deprecated
537 protected String getFieldName(Map<String, String> headers) {
538 return getFieldName(getHeader(headers, CONTENT_DISPOSITION));
539 }
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555 @Deprecated
556 protected FileItem createItem(Map<String, String> headers,
557 boolean isFormField)
558 throws FileUploadException {
559 return getFileItemFactory().createItem(getFieldName(headers),
560 getHeader(headers, CONTENT_TYPE),
561 isFormField,
562 getFileName(headers));
563 }
564
565
566
567
568
569
570
571
572
573
574
575
576
577 protected FileItemHeaders getParsedHeaders(String headerPart) {
578 final int len = headerPart.length();
579 FileItemHeadersImpl headers = newFileItemHeaders();
580 int start = 0;
581 for (;;) {
582 int end = parseEndOfLine(headerPart, start);
583 if (start == end) {
584 break;
585 }
586 StringBuilder header = new StringBuilder(headerPart.substring(start, end));
587 start = end + 2;
588 while (start < len) {
589 int nonWs = start;
590 while (nonWs < len) {
591 char c = headerPart.charAt(nonWs);
592 if (c != ' ' && c != '\t') {
593 break;
594 }
595 ++nonWs;
596 }
597 if (nonWs == start) {
598 break;
599 }
600
601 end = parseEndOfLine(headerPart, nonWs);
602 header.append(" ").append(headerPart.substring(nonWs, end));
603 start = end + 2;
604 }
605 parseHeaderLine(headers, header.toString());
606 }
607 return headers;
608 }
609
610
611
612
613
614 protected FileItemHeadersImpl newFileItemHeaders() {
615 return new FileItemHeadersImpl();
616 }
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631 @Deprecated
632 protected Map<String, String> parseHeaders(String headerPart) {
633 FileItemHeaders headers = getParsedHeaders(headerPart);
634 Map<String, String> result = new HashMap<String, String>();
635 for (Iterator<String> iter = headers.getHeaderNames(); iter.hasNext();) {
636 String headerName = iter.next();
637 Iterator<String> iter2 = headers.getHeaders(headerName);
638 StringBuilder headerValue = new StringBuilder(iter2.next());
639 while (iter2.hasNext()) {
640 headerValue.append(",").append(iter2.next());
641 }
642 result.put(headerName, headerValue.toString());
643 }
644 return result;
645 }
646
647
648
649
650
651
652
653
654
655 private int parseEndOfLine(String headerPart, int end) {
656 int index = end;
657 for (;;) {
658 int offset = headerPart.indexOf('\r', index);
659 if (offset == -1 || offset + 1 >= headerPart.length()) {
660 throw new IllegalStateException(
661 "Expected headers to be terminated by an empty line.");
662 }
663 if (headerPart.charAt(offset + 1) == '\n') {
664 return offset;
665 }
666 index = offset + 1;
667 }
668 }
669
670
671
672
673
674
675 private void parseHeaderLine(FileItemHeadersImpl headers, String header) {
676 final int colonOffset = header.indexOf(':');
677 if (colonOffset == -1) {
678
679 return;
680 }
681 String headerName = header.substring(0, colonOffset).trim();
682 String headerValue =
683 header.substring(header.indexOf(':') + 1).trim();
684 headers.addHeader(headerName, headerValue);
685 }
686
687
688
689
690
691
692
693
694
695
696
697
698 @Deprecated
699 protected final String getHeader(Map<String, String> headers,
700 String name) {
701 return headers.get(name.toLowerCase(Locale.ENGLISH));
702 }
703
704
705
706
707
708 private class FileItemIteratorImpl implements FileItemIterator {
709
710
711
712
713 class FileItemStreamImpl implements FileItemStream {
714
715
716
717
718 private final String contentType;
719
720
721
722
723 private final String fieldName;
724
725
726
727
728 private final String name;
729
730
731
732
733 private final boolean formField;
734
735
736
737
738 private final InputStream stream;
739
740
741
742
743 private boolean opened;
744
745
746
747
748 private FileItemHeaders headers;
749
750
751
752
753
754
755
756
757
758
759
760 FileItemStreamImpl(String pName, String pFieldName,
761 String pContentType, boolean pFormField,
762 long pContentLength) throws IOException {
763 name = pName;
764 fieldName = pFieldName;
765 contentType = pContentType;
766 formField = pFormField;
767 if (fileSizeMax != -1) {
768 if (pContentLength != -1
769 && pContentLength > fileSizeMax) {
770 FileSizeLimitExceededException e =
771 new FileSizeLimitExceededException(
772 format("The field %s exceeds its maximum permitted size of %s bytes.",
773 fieldName, Long.valueOf(fileSizeMax)),
774 pContentLength, fileSizeMax);
775 e.setFileName(pName);
776 e.setFieldName(pFieldName);
777 throw new FileUploadIOException(e);
778 }
779 }
780
781 final ItemInputStream itemStream = multi.newInputStream();
782 InputStream istream = itemStream;
783 if (fileSizeMax != -1) {
784 istream = new LimitedInputStream(istream, fileSizeMax) {
785 @Override
786 protected void raiseError(long pSizeMax, long pCount)
787 throws IOException {
788 itemStream.close(true);
789 FileSizeLimitExceededException e =
790 new FileSizeLimitExceededException(
791 format("The field %s exceeds its maximum permitted size of %s bytes.",
792 fieldName, Long.valueOf(pSizeMax)),
793 pCount, pSizeMax);
794 e.setFieldName(fieldName);
795 e.setFileName(name);
796 throw new FileUploadIOException(e);
797 }
798 };
799 }
800 stream = istream;
801 }
802
803
804
805
806
807
808 @Override
809 public String getContentType() {
810 return contentType;
811 }
812
813
814
815
816
817
818 @Override
819 public String getFieldName() {
820 return fieldName;
821 }
822
823
824
825
826
827
828
829
830
831
832 @Override
833 public String getName() {
834 return Streams.checkFileName(name);
835 }
836
837
838
839
840
841
842
843 @Override
844 public boolean isFormField() {
845 return formField;
846 }
847
848
849
850
851
852
853
854
855 @Override
856 public InputStream openStream() throws IOException {
857 if (opened) {
858 throw new IllegalStateException(
859 "The stream was already opened.");
860 }
861 if (((Closeable) stream).isClosed()) {
862 throw new FileItemStream.ItemSkippedException();
863 }
864 return stream;
865 }
866
867
868
869
870
871
872 void close() throws IOException {
873 stream.close();
874 }
875
876
877
878
879
880
881 @Override
882 public FileItemHeaders getHeaders() {
883 return headers;
884 }
885
886
887
888
889
890
891 @Override
892 public void setHeaders(FileItemHeaders pHeaders) {
893 headers = pHeaders;
894 }
895
896 }
897
898
899
900
901 private final MultipartStream multi;
902
903
904
905
906
907 private final MultipartStream.ProgressNotifier notifier;
908
909
910
911
912 private final byte[] boundary;
913
914
915
916
917 private FileItemStreamImpl currentItem;
918
919
920
921
922 private String currentFieldName;
923
924
925
926
927 private boolean skipPreamble;
928
929
930
931
932 private boolean itemValid;
933
934
935
936
937 private boolean eof;
938
939
940
941
942
943
944
945
946
947 FileItemIteratorImpl(RequestContext ctx)
948 throws FileUploadException, IOException {
949 if (ctx == null) {
950 throw new NullPointerException("ctx parameter");
951 }
952
953 String contentType = ctx.getContentType();
954 if ((null == contentType)
955 || (!contentType.toLowerCase(Locale.ENGLISH).startsWith(MULTIPART))) {
956 throw new InvalidContentTypeException(
957 format("the request doesn't contain a %s or %s stream, content type header is %s",
958 MULTIPART_FORM_DATA, MULTIPART_MIXED, contentType));
959 }
960
961
962 @SuppressWarnings("deprecation")
963 final int contentLengthInt = ctx.getContentLength();
964
965 final long requestSize = UploadContext.class.isAssignableFrom(ctx.getClass())
966
967 ? ((UploadContext) ctx).contentLength()
968 : contentLengthInt;
969
970
971 InputStream input;
972 if (sizeMax >= 0) {
973 if (requestSize != -1 && requestSize > sizeMax) {
974 throw new SizeLimitExceededException(
975 format("the request was rejected because its size (%s) exceeds the configured maximum (%s)",
976 Long.valueOf(requestSize), Long.valueOf(sizeMax)),
977 requestSize, sizeMax);
978 }
979
980 input = new LimitedInputStream(ctx.getInputStream(), sizeMax) {
981 @Override
982 protected void raiseError(long pSizeMax, long pCount)
983 throws IOException {
984 FileUploadException ex = new SizeLimitExceededException(
985 format("the request was rejected because its size (%s) exceeds the configured maximum (%s)",
986 Long.valueOf(pCount), Long.valueOf(pSizeMax)),
987 pCount, pSizeMax);
988 throw new FileUploadIOException(ex);
989 }
990 };
991 } else {
992 input = ctx.getInputStream();
993 }
994
995 String charEncoding = headerEncoding;
996 if (charEncoding == null) {
997 charEncoding = ctx.getCharacterEncoding();
998 }
999
1000 boundary = getBoundary(contentType);
1001 if (boundary == null) {
1002 IOUtils.closeQuietly(input);
1003 throw new FileUploadException("the request was rejected because no multipart boundary was found");
1004 }
1005
1006 notifier = new MultipartStream.ProgressNotifier(listener, requestSize);
1007 try {
1008 multi = new MultipartStream(input, boundary, notifier);
1009 } catch (IllegalArgumentException iae) {
1010 IOUtils.closeQuietly(input);
1011 throw new InvalidContentTypeException(
1012 format("The boundary specified in the %s header is too long", CONTENT_TYPE), iae);
1013 }
1014 multi.setHeaderEncoding(charEncoding);
1015
1016 skipPreamble = true;
1017 findNextItem();
1018 }
1019
1020
1021
1022
1023
1024
1025
1026 private boolean findNextItem() throws IOException {
1027 if (eof) {
1028 return false;
1029 }
1030 if (currentItem != null) {
1031 currentItem.close();
1032 currentItem = null;
1033 }
1034 for (;;) {
1035 boolean nextPart;
1036 if (skipPreamble) {
1037 nextPart = multi.skipPreamble();
1038 } else {
1039 nextPart = multi.readBoundary();
1040 }
1041 if (!nextPart) {
1042 if (currentFieldName == null) {
1043
1044 eof = true;
1045 return false;
1046 }
1047
1048 multi.setBoundary(boundary);
1049 currentFieldName = null;
1050 continue;
1051 }
1052 FileItemHeaders headers = getParsedHeaders(multi.readHeaders());
1053 if (currentFieldName == null) {
1054
1055 String fieldName = getFieldName(headers);
1056 if (fieldName != null) {
1057 String subContentType = headers.getHeader(CONTENT_TYPE);
1058 if (subContentType != null
1059 && subContentType.toLowerCase(Locale.ENGLISH)
1060 .startsWith(MULTIPART_MIXED)) {
1061 currentFieldName = fieldName;
1062
1063 byte[] subBoundary = getBoundary(subContentType);
1064 multi.setBoundary(subBoundary);
1065 skipPreamble = true;
1066 continue;
1067 }
1068 String fileName = getFileName(headers);
1069 currentItem = new FileItemStreamImpl(fileName,
1070 fieldName, headers.getHeader(CONTENT_TYPE),
1071 fileName == null, getContentLength(headers));
1072 currentItem.setHeaders(headers);
1073 notifier.noteItem();
1074 itemValid = true;
1075 return true;
1076 }
1077 } else {
1078 String fileName = getFileName(headers);
1079 if (fileName != null) {
1080 currentItem = new FileItemStreamImpl(fileName,
1081 currentFieldName,
1082 headers.getHeader(CONTENT_TYPE),
1083 false, getContentLength(headers));
1084 currentItem.setHeaders(headers);
1085 notifier.noteItem();
1086 itemValid = true;
1087 return true;
1088 }
1089 }
1090 multi.discardBodyData();
1091 }
1092 }
1093
1094 private long getContentLength(FileItemHeaders pHeaders) {
1095 try {
1096 return Long.parseLong(pHeaders.getHeader(CONTENT_LENGTH));
1097 } catch (Exception e) {
1098 return -1;
1099 }
1100 }
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112 @Override
1113 public boolean hasNext() throws FileUploadException, IOException {
1114 if (eof) {
1115 return false;
1116 }
1117 if (itemValid) {
1118 return true;
1119 }
1120 try {
1121 return findNextItem();
1122 } catch (FileUploadIOException e) {
1123
1124 throw (FileUploadException) e.getCause();
1125 }
1126 }
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139 @Override
1140 public FileItemStream next() throws FileUploadException, IOException {
1141 if (eof || (!itemValid && !hasNext())) {
1142 throw new NoSuchElementException();
1143 }
1144 itemValid = false;
1145 return currentItem;
1146 }
1147
1148 }
1149
1150
1151
1152
1153
1154 public static class FileUploadIOException extends IOException {
1155
1156
1157
1158
1159 private static final long serialVersionUID = -7047616958165584154L;
1160
1161
1162
1163
1164
1165
1166 private final FileUploadException cause;
1167
1168
1169
1170
1171
1172
1173
1174 public FileUploadIOException(FileUploadException pCause) {
1175
1176 cause = pCause;
1177 }
1178
1179
1180
1181
1182
1183
1184 @Override
1185 public Throwable getCause() {
1186 return cause;
1187 }
1188
1189 }
1190
1191
1192
1193
1194 public static class InvalidContentTypeException
1195 extends FileUploadException {
1196
1197
1198
1199
1200 private static final long serialVersionUID = -9073026332015646668L;
1201
1202
1203
1204
1205
1206 public InvalidContentTypeException() {
1207 super();
1208 }
1209
1210
1211
1212
1213
1214
1215
1216 public InvalidContentTypeException(String message) {
1217 super(message);
1218 }
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229 public InvalidContentTypeException(String msg, Throwable cause) {
1230 super(msg, cause);
1231 }
1232 }
1233
1234
1235
1236
1237 public static class IOFileUploadException extends FileUploadException {
1238
1239
1240
1241
1242 private static final long serialVersionUID = 1749796615868477269L;
1243
1244
1245
1246
1247
1248
1249 private final IOException cause;
1250
1251
1252
1253
1254
1255
1256
1257 public IOFileUploadException(String pMsg, IOException pException) {
1258 super(pMsg);
1259 cause = pException;
1260 }
1261
1262
1263
1264
1265
1266
1267 @Override
1268 public Throwable getCause() {
1269 return cause;
1270 }
1271
1272 }
1273
1274
1275
1276
1277
1278 protected abstract static class SizeException extends FileUploadException {
1279
1280
1281
1282
1283 private static final long serialVersionUID = -8776225574705254126L;
1284
1285
1286
1287
1288 private final long actual;
1289
1290
1291
1292
1293 private final long permitted;
1294
1295
1296
1297
1298
1299
1300
1301
1302 protected SizeException(String message, long actual, long permitted) {
1303 super(message);
1304 this.actual = actual;
1305 this.permitted = permitted;
1306 }
1307
1308
1309
1310
1311
1312
1313
1314 public long getActualSize() {
1315 return actual;
1316 }
1317
1318
1319
1320
1321
1322
1323
1324 public long getPermittedSize() {
1325 return permitted;
1326 }
1327
1328 }
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338 @Deprecated
1339 public static class UnknownSizeException
1340 extends FileUploadException {
1341
1342
1343
1344
1345 private static final long serialVersionUID = 7062279004812015273L;
1346
1347
1348
1349
1350
1351 public UnknownSizeException() {
1352 super();
1353 }
1354
1355
1356
1357
1358
1359
1360
1361 public UnknownSizeException(String message) {
1362 super(message);
1363 }
1364
1365 }
1366
1367
1368
1369
1370 public static class SizeLimitExceededException
1371 extends SizeException {
1372
1373
1374
1375
1376 private static final long serialVersionUID = -2474893167098052828L;
1377
1378
1379
1380
1381
1382 @Deprecated
1383 public SizeLimitExceededException() {
1384 this(null, 0, 0);
1385 }
1386
1387
1388
1389
1390
1391
1392 @Deprecated
1393 public SizeLimitExceededException(String message) {
1394 this(message, 0, 0);
1395 }
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405 public SizeLimitExceededException(String message, long actual,
1406 long permitted) {
1407 super(message, actual, permitted);
1408 }
1409
1410 }
1411
1412
1413
1414
1415 public static class FileSizeLimitExceededException
1416 extends SizeException {
1417
1418
1419
1420
1421 private static final long serialVersionUID = 8150776562029630058L;
1422
1423
1424
1425
1426 private String fileName;
1427
1428
1429
1430
1431 private String fieldName;
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441 public FileSizeLimitExceededException(String message, long actual,
1442 long permitted) {
1443 super(message, actual, permitted);
1444 }
1445
1446
1447
1448
1449
1450
1451
1452 public String getFileName() {
1453 return fileName;
1454 }
1455
1456
1457
1458
1459
1460
1461
1462 public void setFileName(String pFileName) {
1463 fileName = pFileName;
1464 }
1465
1466
1467
1468
1469
1470
1471
1472 public String getFieldName() {
1473 return fieldName;
1474 }
1475
1476
1477
1478
1479
1480
1481
1482
1483 public void setFieldName(String pFieldName) {
1484 fieldName = pFieldName;
1485 }
1486
1487 }
1488
1489
1490
1491
1492
1493
1494 public ProgressListener getProgressListener() {
1495 return listener;
1496 }
1497
1498
1499
1500
1501
1502
1503 public void setProgressListener(ProgressListener pListener) {
1504 listener = pListener;
1505 }
1506
1507 }