2727import org .springframework .util .ObjectUtils ;
2828import org .springframework .util .StringUtils ;
2929
30- import static java .nio .charset .StandardCharsets .ISO_8859_1 ;
31- import static java .nio .charset .StandardCharsets .UTF_8 ;
32- import static java .time .format .DateTimeFormatter .RFC_1123_DATE_TIME ;
30+ import static java .nio .charset .StandardCharsets .*;
31+ import static java .time .format .DateTimeFormatter .*;
3332
3433/**
3534 * Represent the Content-Disposition type and parameters as defined in RFC 2183.
@@ -151,6 +150,85 @@ public ZonedDateTime getReadDate() {
151150 }
152151
153152
153+ @ Override
154+ public boolean equals (Object other ) {
155+ if (this == other ) {
156+ return true ;
157+ }
158+ if (!(other instanceof ContentDisposition )) {
159+ return false ;
160+ }
161+ ContentDisposition otherCd = (ContentDisposition ) other ;
162+ return (ObjectUtils .nullSafeEquals (this .type , otherCd .type ) &&
163+ ObjectUtils .nullSafeEquals (this .name , otherCd .name ) &&
164+ ObjectUtils .nullSafeEquals (this .filename , otherCd .filename ) &&
165+ ObjectUtils .nullSafeEquals (this .charset , otherCd .charset ) &&
166+ ObjectUtils .nullSafeEquals (this .size , otherCd .size ) &&
167+ ObjectUtils .nullSafeEquals (this .creationDate , otherCd .creationDate )&&
168+ ObjectUtils .nullSafeEquals (this .modificationDate , otherCd .modificationDate )&&
169+ ObjectUtils .nullSafeEquals (this .readDate , otherCd .readDate ));
170+ }
171+
172+ @ Override
173+ public int hashCode () {
174+ int result = ObjectUtils .nullSafeHashCode (this .type );
175+ result = 31 * result + ObjectUtils .nullSafeHashCode (this .name );
176+ result = 31 * result + ObjectUtils .nullSafeHashCode (this .filename );
177+ result = 31 * result + ObjectUtils .nullSafeHashCode (this .charset );
178+ result = 31 * result + ObjectUtils .nullSafeHashCode (this .size );
179+ result = 31 * result + (creationDate != null ? creationDate .hashCode () : 0 );
180+ result = 31 * result + (modificationDate != null ? modificationDate .hashCode () : 0 );
181+ result = 31 * result + (readDate != null ? readDate .hashCode () : 0 );
182+ return result ;
183+ }
184+
185+ /**
186+ * Return the header value for this content disposition as defined in RFC 2183.
187+ * @see #parse(String)
188+ */
189+ @ Override
190+ public String toString () {
191+ StringBuilder sb = new StringBuilder ();
192+ if (this .type != null ) {
193+ sb .append (this .type );
194+ }
195+ if (this .name != null ) {
196+ sb .append ("; name=\" " );
197+ sb .append (this .name ).append ('\"' );
198+ }
199+ if (this .filename != null ) {
200+ if (this .charset == null || StandardCharsets .US_ASCII .equals (this .charset )) {
201+ sb .append ("; filename=\" " );
202+ sb .append (this .filename ).append ('\"' );
203+ }
204+ else {
205+ sb .append ("; filename*=" );
206+ sb .append (encodeHeaderFieldParam (this .filename , this .charset ));
207+ }
208+ }
209+ if (this .size != null ) {
210+ sb .append ("; size=" );
211+ sb .append (this .size );
212+ }
213+ if (this .creationDate != null ) {
214+ sb .append ("; creation-date=\" " );
215+ sb .append (RFC_1123_DATE_TIME .format (this .creationDate ));
216+ sb .append ('\"' );
217+ }
218+ if (this .modificationDate != null ) {
219+ sb .append ("; modification-date=\" " );
220+ sb .append (RFC_1123_DATE_TIME .format (this .modificationDate ));
221+ sb .append ('\"' );
222+ }
223+ if (this .readDate != null ) {
224+ sb .append ("; read-date=\" " );
225+ sb .append (RFC_1123_DATE_TIME .format (this .readDate ));
226+ sb .append ('\"' );
227+ }
228+ return sb .toString ();
229+ }
230+
231+
154232 /**
155233 * Return a builder for a {@code ContentDisposition}.
156234 * @param type the disposition type like for example {@literal inline},
@@ -170,7 +248,6 @@ public static ContentDisposition empty() {
170248
171249 /**
172250 * Parse a {@literal Content-Disposition} header value as defined in RFC 2183.
173- *
174251 * @param contentDisposition the {@literal Content-Disposition} header value
175252 * @return the parsed content disposition
176253 * @see #toString()
@@ -286,84 +363,6 @@ private static boolean isRFC5987AttrChar(byte c) {
286363 c == '.' || c == '^' || c == '_' || c == '`' || c == '|' || c == '~' ;
287364 }
288365
289- @ Override
290- public boolean equals (Object other ) {
291- if (this == other ) {
292- return true ;
293- }
294- if (!(other instanceof ContentDisposition )) {
295- return false ;
296- }
297- ContentDisposition otherCd = (ContentDisposition ) other ;
298- return (ObjectUtils .nullSafeEquals (this .type , otherCd .type ) &&
299- ObjectUtils .nullSafeEquals (this .name , otherCd .name ) &&
300- ObjectUtils .nullSafeEquals (this .filename , otherCd .filename ) &&
301- ObjectUtils .nullSafeEquals (this .charset , otherCd .charset ) &&
302- ObjectUtils .nullSafeEquals (this .size , otherCd .size ) &&
303- ObjectUtils .nullSafeEquals (this .creationDate , otherCd .creationDate )&&
304- ObjectUtils .nullSafeEquals (this .modificationDate , otherCd .modificationDate )&&
305- ObjectUtils .nullSafeEquals (this .readDate , otherCd .readDate ));
306- }
307-
308- @ Override
309- public int hashCode () {
310- int result = ObjectUtils .nullSafeHashCode (this .type );
311- result = 31 * result + ObjectUtils .nullSafeHashCode (this .name );
312- result = 31 * result + ObjectUtils .nullSafeHashCode (this .filename );
313- result = 31 * result + ObjectUtils .nullSafeHashCode (this .charset );
314- result = 31 * result + ObjectUtils .nullSafeHashCode (this .size );
315- result = 31 * result + (creationDate != null ? creationDate .hashCode () : 0 );
316- result = 31 * result + (modificationDate != null ? modificationDate .hashCode () : 0 );
317- result = 31 * result + (readDate != null ? readDate .hashCode () : 0 );
318- return result ;
319- }
320-
321- /**
322- * Return the header value for this content disposition as defined in RFC 2183.
323- * @see #parse(String)
324- */
325- @ Override
326- public String toString () {
327- StringBuilder sb = new StringBuilder ();
328- if (this .type != null ) {
329- sb .append (this .type );
330- }
331- if (this .name != null ) {
332- sb .append ("; name=\" " );
333- sb .append (this .name ).append ('\"' );
334- }
335- if (this .filename != null ) {
336- if (this .charset == null || StandardCharsets .US_ASCII .equals (this .charset )) {
337- sb .append ("; filename=\" " );
338- sb .append (this .filename ).append ('\"' );
339- }
340- else {
341- sb .append ("; filename*=" );
342- sb .append (encodeHeaderFieldParam (this .filename , this .charset ));
343- }
344- }
345- if (this .size != null ) {
346- sb .append ("; size=" );
347- sb .append (this .size );
348- }
349- if (this .creationDate != null ) {
350- sb .append ("; creation-date=\" " );
351- sb .append (RFC_1123_DATE_TIME .format (this .creationDate ));
352- sb .append ('\"' );
353- }
354- if (this .modificationDate != null ) {
355- sb .append ("; modification-date=\" " );
356- sb .append (RFC_1123_DATE_TIME .format (this .modificationDate ));
357- sb .append ('\"' );
358- }
359- if (this .readDate != null ) {
360- sb .append ("; read-date=\" " );
361- sb .append (RFC_1123_DATE_TIME .format (this .readDate ));
362- sb .append ('\"' );
363- }
364- return sb .toString ();
365- }
366-
367366 /**
368367 * Encode the given header field param as describe in RFC 5987.
369368 * @param input the header field param
0 commit comments