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