1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import java .nio .charset .Charset ;
21
21
import java .nio .charset .StandardCharsets ;
22
22
import java .time .ZonedDateTime ;
23
- import java .time .format .DateTimeParseException ;
24
23
import java .util .ArrayList ;
25
24
import java .util .Base64 ;
26
25
import java .util .BitSet ;
36
35
import static java .nio .charset .StandardCharsets .ISO_8859_1 ;
37
36
import static java .nio .charset .StandardCharsets .US_ASCII ;
38
37
import static java .nio .charset .StandardCharsets .UTF_8 ;
39
- import static java .time .format .DateTimeFormatter .RFC_1123_DATE_TIME ;
40
38
41
39
/**
42
40
* Representation of the Content-Disposition type and parameters as defined in RFC 6266.
@@ -85,34 +83,17 @@ public final class ContentDisposition {
85
83
@ Nullable
86
84
private final Charset charset ;
87
85
88
- @ Nullable
89
- private final Long size ;
90
-
91
- @ Nullable
92
- private final ZonedDateTime creationDate ;
93
-
94
- @ Nullable
95
- private final ZonedDateTime modificationDate ;
96
-
97
- @ Nullable
98
- private final ZonedDateTime readDate ;
99
-
100
86
101
87
/**
102
88
* Private constructor. See static factory methods in this class.
103
89
*/
104
90
private ContentDisposition (@ Nullable String type , @ Nullable String name , @ Nullable String filename ,
105
- @ Nullable Charset charset , @ Nullable Long size , @ Nullable ZonedDateTime creationDate ,
106
- @ Nullable ZonedDateTime modificationDate , @ Nullable ZonedDateTime readDate ) {
91
+ @ Nullable Charset charset ) {
107
92
108
93
this .type = type ;
109
94
this .name = name ;
110
95
this .filename = filename ;
111
96
this .charset = charset ;
112
- this .size = size ;
113
- this .creationDate = creationDate ;
114
- this .modificationDate = modificationDate ;
115
- this .readDate = readDate ;
116
97
}
117
98
118
99
@@ -177,71 +158,19 @@ public Charset getCharset() {
177
158
return this .charset ;
178
159
}
179
160
180
- /**
181
- * Return the value of the {@literal size} parameter, or {@code null} if not defined.
182
- * @deprecated since 5.2.3 as per
183
- * <a href="https://tools.ietf.org/html/rfc6266#appendix-B">RFC 6266, Appendix B</a>,
184
- * to be removed in a future release.
185
- */
186
- @ Deprecated
187
- @ Nullable
188
- public Long getSize () {
189
- return this .size ;
190
- }
191
-
192
- /**
193
- * Return the value of the {@literal creation-date} parameter, or {@code null} if not defined.
194
- * @deprecated since 5.2.3 as per
195
- * <a href="https://tools.ietf.org/html/rfc6266#appendix-B">RFC 6266, Appendix B</a>,
196
- * to be removed in a future release.
197
- */
198
- @ Deprecated
199
- @ Nullable
200
- public ZonedDateTime getCreationDate () {
201
- return this .creationDate ;
202
- }
203
-
204
- /**
205
- * Return the value of the {@literal modification-date} parameter, or {@code null} if not defined.
206
- * @deprecated since 5.2.3 as per
207
- * <a href="https://tools.ietf.org/html/rfc6266#appendix-B">RFC 6266, Appendix B</a>,
208
- * to be removed in a future release.
209
- */
210
- @ Deprecated
211
- @ Nullable
212
- public ZonedDateTime getModificationDate () {
213
- return this .modificationDate ;
214
- }
215
-
216
- /**
217
- * Return the value of the {@literal read-date} parameter, or {@code null} if not defined.
218
- * @deprecated since 5.2.3 as per
219
- * <a href="https://tools.ietf.org/html/rfc6266#appendix-B">RFC 6266, Appendix B</a>,
220
- * to be removed in a future release.
221
- */
222
- @ Deprecated
223
- @ Nullable
224
- public ZonedDateTime getReadDate () {
225
- return this .readDate ;
226
- }
227
161
228
162
@ Override
229
163
public boolean equals (@ Nullable Object other ) {
230
164
return (this == other || (other instanceof ContentDisposition that &&
231
165
ObjectUtils .nullSafeEquals (this .type , that .type ) &&
232
166
ObjectUtils .nullSafeEquals (this .name , that .name ) &&
233
167
ObjectUtils .nullSafeEquals (this .filename , that .filename ) &&
234
- ObjectUtils .nullSafeEquals (this .charset , that .charset ) &&
235
- ObjectUtils .nullSafeEquals (this .size , that .size ) &&
236
- ObjectUtils .nullSafeEquals (this .creationDate , that .creationDate )&&
237
- ObjectUtils .nullSafeEquals (this .modificationDate , that .modificationDate )&&
238
- ObjectUtils .nullSafeEquals (this .readDate , that .readDate )));
168
+ ObjectUtils .nullSafeEquals (this .charset , that .charset )));
239
169
}
240
170
241
171
@ Override
242
172
public int hashCode () {
243
- return ObjectUtils .nullSafeHash (this .type , this .name ,this .filename ,
244
- this .charset , this .size , this .creationDate , this .modificationDate , this .readDate );
173
+ return ObjectUtils .nullSafeHash (this .type , this .name ,this .filename , this .charset );
245
174
}
246
175
247
176
/**
@@ -270,25 +199,6 @@ public String toString() {
270
199
sb .append (encodeRfc5987Filename (this .filename , this .charset ));
271
200
}
272
201
}
273
- if (this .size != null ) {
274
- sb .append ("; size=" );
275
- sb .append (this .size );
276
- }
277
- if (this .creationDate != null ) {
278
- sb .append ("; creation-date=\" " );
279
- sb .append (RFC_1123_DATE_TIME .format (this .creationDate ));
280
- sb .append ('\"' );
281
- }
282
- if (this .modificationDate != null ) {
283
- sb .append ("; modification-date=\" " );
284
- sb .append (RFC_1123_DATE_TIME .format (this .modificationDate ));
285
- sb .append ('\"' );
286
- }
287
- if (this .readDate != null ) {
288
- sb .append ("; read-date=\" " );
289
- sb .append (RFC_1123_DATE_TIME .format (this .readDate ));
290
- sb .append ('\"' );
291
- }
292
202
return sb .toString ();
293
203
}
294
204
@@ -331,7 +241,7 @@ public static Builder builder(String type) {
331
241
* Return an empty content disposition.
332
242
*/
333
243
public static ContentDisposition empty () {
334
- return new ContentDisposition ("" , null , null , null , null , null , null , null );
244
+ return new ContentDisposition ("" , null , null , null );
335
245
}
336
246
337
247
/**
@@ -376,7 +286,7 @@ else if (attribute.equals("filename*") ) {
376
286
}
377
287
}
378
288
else if (attribute .equals ("filename" ) && (filename == null )) {
379
- if (value .startsWith ("=?" ) ) {
289
+ if (value .startsWith ("=?" )) {
380
290
Matcher matcher = BASE64_ENCODED_PATTERN .matcher (value );
381
291
if (matcher .find ()) {
382
292
Base64 .Decoder decoder = Base64 .getDecoder ();
@@ -415,39 +325,12 @@ else if (value.indexOf('\\') != -1) {
415
325
filename = value ;
416
326
}
417
327
}
418
- else if (attribute .equals ("size" ) ) {
419
- size = Long .parseLong (value );
420
- }
421
- else if (attribute .equals ("creation-date" )) {
422
- try {
423
- creationDate = ZonedDateTime .parse (value , RFC_1123_DATE_TIME );
424
- }
425
- catch (DateTimeParseException ex ) {
426
- // ignore
427
- }
428
- }
429
- else if (attribute .equals ("modification-date" )) {
430
- try {
431
- modificationDate = ZonedDateTime .parse (value , RFC_1123_DATE_TIME );
432
- }
433
- catch (DateTimeParseException ex ) {
434
- // ignore
435
- }
436
- }
437
- else if (attribute .equals ("read-date" )) {
438
- try {
439
- readDate = ZonedDateTime .parse (value , RFC_1123_DATE_TIME );
440
- }
441
- catch (DateTimeParseException ex ) {
442
- // ignore
443
- }
444
- }
445
328
}
446
329
else {
447
330
throw new IllegalArgumentException ("Invalid content disposition format" );
448
331
}
449
332
}
450
- return new ContentDisposition (type , name , filename , charset , size , creationDate , modificationDate , readDate );
333
+ return new ContentDisposition (type , name , filename , charset );
451
334
}
452
335
453
336
private static List <String > tokenize (String headerValue ) {
@@ -714,42 +597,6 @@ public interface Builder {
714
597
*/
715
598
Builder filename (@ Nullable String filename , @ Nullable Charset charset );
716
599
717
- /**
718
- * Set the value of the {@literal size} parameter.
719
- * @deprecated since 5.2.3 as per
720
- * <a href="https://tools.ietf.org/html/rfc6266#appendix-B">RFC 6266, Appendix B</a>,
721
- * to be removed in a future release.
722
- */
723
- @ Deprecated
724
- Builder size (@ Nullable Long size );
725
-
726
- /**
727
- * Set the value of the {@literal creation-date} parameter.
728
- * @deprecated since 5.2.3 as per
729
- * <a href="https://tools.ietf.org/html/rfc6266#appendix-B">RFC 6266, Appendix B</a>,
730
- * to be removed in a future release.
731
- */
732
- @ Deprecated
733
- Builder creationDate (@ Nullable ZonedDateTime creationDate );
734
-
735
- /**
736
- * Set the value of the {@literal modification-date} parameter.
737
- * @deprecated since 5.2.3 as per
738
- * <a href="https://tools.ietf.org/html/rfc6266#appendix-B">RFC 6266, Appendix B</a>,
739
- * to be removed in a future release.
740
- */
741
- @ Deprecated
742
- Builder modificationDate (@ Nullable ZonedDateTime modificationDate );
743
-
744
- /**
745
- * Set the value of the {@literal read-date} parameter.
746
- * @deprecated since 5.2.3 as per
747
- * <a href="https://tools.ietf.org/html/rfc6266#appendix-B">RFC 6266, Appendix B</a>,
748
- * to be removed in a future release.
749
- */
750
- @ Deprecated
751
- Builder readDate (@ Nullable ZonedDateTime readDate );
752
-
753
600
/**
754
601
* Build the content disposition.
755
602
*/
@@ -770,17 +617,6 @@ private static class BuilderImpl implements Builder {
770
617
@ Nullable
771
618
private Charset charset ;
772
619
773
- @ Nullable
774
- private Long size ;
775
-
776
- @ Nullable
777
- private ZonedDateTime creationDate ;
778
-
779
- @ Nullable
780
- private ZonedDateTime modificationDate ;
781
-
782
- @ Nullable
783
- private ZonedDateTime readDate ;
784
620
785
621
public BuilderImpl (String type ) {
786
622
Assert .hasText (type , "'type' must not be not empty" );
@@ -806,38 +642,9 @@ public Builder filename(@Nullable String filename, @Nullable Charset charset) {
806
642
return this ;
807
643
}
808
644
809
- @ Override
810
- @ SuppressWarnings ("deprecation" )
811
- public Builder size (@ Nullable Long size ) {
812
- this .size = size ;
813
- return this ;
814
- }
815
-
816
- @ Override
817
- @ SuppressWarnings ("deprecation" )
818
- public Builder creationDate (@ Nullable ZonedDateTime creationDate ) {
819
- this .creationDate = creationDate ;
820
- return this ;
821
- }
822
-
823
- @ Override
824
- @ SuppressWarnings ("deprecation" )
825
- public Builder modificationDate (@ Nullable ZonedDateTime modificationDate ) {
826
- this .modificationDate = modificationDate ;
827
- return this ;
828
- }
829
-
830
- @ Override
831
- @ SuppressWarnings ("deprecation" )
832
- public Builder readDate (@ Nullable ZonedDateTime readDate ) {
833
- this .readDate = readDate ;
834
- return this ;
835
- }
836
-
837
645
@ Override
838
646
public ContentDisposition build () {
839
- return new ContentDisposition (this .type , this .name , this .filename , this .charset ,
840
- this .size , this .creationDate , this .modificationDate , this .readDate );
647
+ return new ContentDisposition (this .type , this .name , this .filename , this .charset );
841
648
}
842
649
}
843
650
0 commit comments