@ -27,9 +27,8 @@ import org.springframework.util.Assert;
@@ -27,9 +27,8 @@ import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils ;
import org.springframework.util.StringUtils ;
import static java.nio.charset.StandardCharsets.ISO_8859_1 ;
import static java.nio.charset.StandardCharsets.UTF_8 ;
import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME ;
import static java.nio.charset.StandardCharsets.* ;
import static java.time.format.DateTimeFormatter.* ;
/ * *
* Represent the Content - Disposition type and parameters as defined in RFC 2183 .
@ -151,6 +150,85 @@ public class ContentDisposition {
@@ -151,6 +150,85 @@ public class ContentDisposition {
}
@Override
public boolean equals ( Object other ) {
if ( this = = other ) {
return true ;
}
if ( ! ( other instanceof ContentDisposition ) ) {
return false ;
}
ContentDisposition otherCd = ( ContentDisposition ) other ;
return ( ObjectUtils . nullSafeEquals ( this . type , otherCd . type ) & &
ObjectUtils . nullSafeEquals ( this . name , otherCd . name ) & &
ObjectUtils . nullSafeEquals ( this . filename , otherCd . filename ) & &
ObjectUtils . nullSafeEquals ( this . charset , otherCd . charset ) & &
ObjectUtils . nullSafeEquals ( this . size , otherCd . size ) & &
ObjectUtils . nullSafeEquals ( this . creationDate , otherCd . creationDate ) & &
ObjectUtils . nullSafeEquals ( this . modificationDate , otherCd . modificationDate ) & &
ObjectUtils . nullSafeEquals ( this . readDate , otherCd . readDate ) ) ;
}
@Override
public int hashCode ( ) {
int result = ObjectUtils . nullSafeHashCode ( this . type ) ;
result = 31 * result + ObjectUtils . nullSafeHashCode ( this . name ) ;
result = 31 * result + ObjectUtils . nullSafeHashCode ( this . filename ) ;
result = 31 * result + ObjectUtils . nullSafeHashCode ( this . charset ) ;
result = 31 * result + ObjectUtils . nullSafeHashCode ( this . size ) ;
result = 31 * result + ( creationDate ! = null ? creationDate . hashCode ( ) : 0 ) ;
result = 31 * result + ( modificationDate ! = null ? modificationDate . hashCode ( ) : 0 ) ;
result = 31 * result + ( readDate ! = null ? readDate . hashCode ( ) : 0 ) ;
return result ;
}
/ * *
* Return the header value for this content disposition as defined in RFC 2183 .
* @see # parse ( String )
* /
@Override
public String toString ( ) {
StringBuilder sb = new StringBuilder ( ) ;
if ( this . type ! = null ) {
sb . append ( this . type ) ;
}
if ( this . name ! = null ) {
sb . append ( "; name=\"" ) ;
sb . append ( this . name ) . append ( '\"' ) ;
}
if ( this . filename ! = null ) {
if ( this . charset = = null | | StandardCharsets . US_ASCII . equals ( this . charset ) ) {
sb . append ( "; filename=\"" ) ;
sb . append ( this . filename ) . append ( '\"' ) ;
}
else {
sb . append ( "; filename*=" ) ;
sb . append ( encodeHeaderFieldParam ( this . filename , this . charset ) ) ;
}
}
if ( this . size ! = null ) {
sb . append ( "; size=" ) ;
sb . append ( this . size ) ;
}
if ( this . creationDate ! = null ) {
sb . append ( "; creation-date=\"" ) ;
sb . append ( RFC_1123_DATE_TIME . format ( this . creationDate ) ) ;
sb . append ( '\"' ) ;
}
if ( this . modificationDate ! = null ) {
sb . append ( "; modification-date=\"" ) ;
sb . append ( RFC_1123_DATE_TIME . format ( this . modificationDate ) ) ;
sb . append ( '\"' ) ;
}
if ( this . readDate ! = null ) {
sb . append ( "; read-date=\"" ) ;
sb . append ( RFC_1123_DATE_TIME . format ( this . readDate ) ) ;
sb . append ( '\"' ) ;
}
return sb . toString ( ) ;
}
/ * *
* Return a builder for a { @code ContentDisposition } .
* @param type the disposition type like for example { @literal inline } ,
@ -170,7 +248,6 @@ public class ContentDisposition {
@@ -170,7 +248,6 @@ public class ContentDisposition {
/ * *
* Parse a { @literal Content - Disposition } header value as defined in RFC 2183 .
*
* @param contentDisposition the { @literal Content - Disposition } header value
* @return the parsed content disposition
* @see # toString ( )
@ -286,84 +363,6 @@ public class ContentDisposition {
@@ -286,84 +363,6 @@ public class ContentDisposition {
c = = '.' | | c = = '^' | | c = = '_' | | c = = '`' | | c = = '|' | | c = = '~' ;
}
@Override
public boolean equals ( Object other ) {
if ( this = = other ) {
return true ;
}
if ( ! ( other instanceof ContentDisposition ) ) {
return false ;
}
ContentDisposition otherCd = ( ContentDisposition ) other ;
return ( ObjectUtils . nullSafeEquals ( this . type , otherCd . type ) & &
ObjectUtils . nullSafeEquals ( this . name , otherCd . name ) & &
ObjectUtils . nullSafeEquals ( this . filename , otherCd . filename ) & &
ObjectUtils . nullSafeEquals ( this . charset , otherCd . charset ) & &
ObjectUtils . nullSafeEquals ( this . size , otherCd . size ) & &
ObjectUtils . nullSafeEquals ( this . creationDate , otherCd . creationDate ) & &
ObjectUtils . nullSafeEquals ( this . modificationDate , otherCd . modificationDate ) & &
ObjectUtils . nullSafeEquals ( this . readDate , otherCd . readDate ) ) ;
}
@Override
public int hashCode ( ) {
int result = ObjectUtils . nullSafeHashCode ( this . type ) ;
result = 31 * result + ObjectUtils . nullSafeHashCode ( this . name ) ;
result = 31 * result + ObjectUtils . nullSafeHashCode ( this . filename ) ;
result = 31 * result + ObjectUtils . nullSafeHashCode ( this . charset ) ;
result = 31 * result + ObjectUtils . nullSafeHashCode ( this . size ) ;
result = 31 * result + ( creationDate ! = null ? creationDate . hashCode ( ) : 0 ) ;
result = 31 * result + ( modificationDate ! = null ? modificationDate . hashCode ( ) : 0 ) ;
result = 31 * result + ( readDate ! = null ? readDate . hashCode ( ) : 0 ) ;
return result ;
}
/ * *
* Return the header value for this content disposition as defined in RFC 2183 .
* @see # parse ( String )
* /
@Override
public String toString ( ) {
StringBuilder sb = new StringBuilder ( ) ;
if ( this . type ! = null ) {
sb . append ( this . type ) ;
}
if ( this . name ! = null ) {
sb . append ( "; name=\"" ) ;
sb . append ( this . name ) . append ( '\"' ) ;
}
if ( this . filename ! = null ) {
if ( this . charset = = null | | StandardCharsets . US_ASCII . equals ( this . charset ) ) {
sb . append ( "; filename=\"" ) ;
sb . append ( this . filename ) . append ( '\"' ) ;
}
else {
sb . append ( "; filename*=" ) ;
sb . append ( encodeHeaderFieldParam ( this . filename , this . charset ) ) ;
}
}
if ( this . size ! = null ) {
sb . append ( "; size=" ) ;
sb . append ( this . size ) ;
}
if ( this . creationDate ! = null ) {
sb . append ( "; creation-date=\"" ) ;
sb . append ( RFC_1123_DATE_TIME . format ( this . creationDate ) ) ;
sb . append ( '\"' ) ;
}
if ( this . modificationDate ! = null ) {
sb . append ( "; modification-date=\"" ) ;
sb . append ( RFC_1123_DATE_TIME . format ( this . modificationDate ) ) ;
sb . append ( '\"' ) ;
}
if ( this . readDate ! = null ) {
sb . append ( "; read-date=\"" ) ;
sb . append ( RFC_1123_DATE_TIME . format ( this . readDate ) ) ;
sb . append ( '\"' ) ;
}
return sb . toString ( ) ;
}
/ * *
* Encode the given header field param as describe in RFC 5987 .
* @param input the header field param