Top Description Inners Fields Constructors Methods
org.springframework.http

public final Class ContentDisposition

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, java.nio.charset.Charset, .StandardCharsets, java.time.ZonedDateTime, java.time.format.DateTimeParseException, java.util.ArrayList, .Base64, .BitSet, .List, java.util.regex.Matcher, .Pattern, org.springframework.lang.Nullable, org.springframework.util.Assert, .ObjectUtils, .StreamUtils

Representation of the Content-Disposition type and parameters as defined in RFC 6266.
Authors
Sebastien Deleuze, Juergen Hoeller, Rossen Stoyanchev, Sergey Tsypanov
Since
5.0
See Also
RFC 6266

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ContentDisposition.Builder

A mutable builder for ContentDisposition.

private static class

Field Summary

Modifier and TypeField and Description
private static final Pattern
private final Charset
private final ZonedDateTime
private final String
private static final String
private final ZonedDateTime
private final String
private static final BitSet
private static final Pattern
private final ZonedDateTime
private final Long
private final String

Constructor Summary

AccessConstructor and Description
private
ContentDisposition(String type, String name, String filename, Charset charset, Long size, ZonedDateTime creationDate, ZonedDateTime modificationDate, ZonedDateTime readDate)

Private constructor.

Method Summary

Modifier and TypeMethod and Description
public static ContentDisposition.Builder
attachment()

Return a builder for a ContentDisposition of type "attachment".

public static ContentDisposition.Builder

Returns:

the builder
builder
(String
the disposition type like for example inline, attachment, or form-data
type
)

Return a builder for a ContentDisposition.

private static String
private static String

Returns:

the decoded header field param
decodeQuotedPrintableFilename
(String
the filename
filename
,
Charset
the charset for the filename
charset
)

Decode the given header field param as described in RFC 2047.

private static String

Returns:

the encoded header field param
decodeRfc5987Filename
(String
the filename
filename
,
Charset
the charset for the filename
charset
)

Decode the given header field param as described in RFC 5987.

public static ContentDisposition
empty()

Return an empty content disposition.

private static String
private static String

Returns:

the encoded header field param
encodeQuotedPrintableFilename
(String
the filename
filename
,
Charset
the charset for the filename
charset
)

Encode the given header field param as described in RFC 2047.

private static String

Returns:

the encoded header field param
encodeRfc5987Filename
(String
the header field param
input
,
Charset
the charset of the header field param string, only the US-ASCII, UTF-8 and ISO-8859-1 charsets are supported
charset
)

Encode the given header field param as describe in RFC 5987.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public static ContentDisposition.Builder
formData()

Return a builder for a ContentDisposition of type "form-data".

public Charset
getCharset()

Return the charset defined in filename* parameter, or null if not defined.

public ZonedDateTime
getCreationDate()

Deprecated since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.
Return the value of the creation-date parameter, or null if not defined.
public String
getFilename()

Return the value of the filename parameter, possibly decoded from BASE64 encoding based on RFC 2047, or of the filename* parameter, possibly decoded as defined in the RFC 5987.

public ZonedDateTime
getModificationDate()

Deprecated since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.
Return the value of the modification-date parameter, or null if not defined.
public String
getName()

Return the value of the name parameter, or null if not defined.

public ZonedDateTime
getReadDate()

Deprecated since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.
Return the value of the read-date parameter, or null if not defined.
public Long
getSize()

Deprecated since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.
Return the value of the size parameter, or null if not defined.
public String
getType()

Return the disposition type.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
private static char
hexDigit(int b)

public static ContentDisposition.Builder
inline()

Return a builder for a ContentDisposition of type "inline".

public boolean
isAttachment()

Return whether the type is "attachment".

public boolean
isFormData()

Return whether the type is "form-data".

public boolean
isInline()

Return whether the type is "inline".

private static boolean
isPrintable(byte c)

private static boolean
public static ContentDisposition

Returns:

the parsed content disposition
parse
(String
the Content-Disposition header value
contentDisposition
)

Parse a Content-Disposition header value as defined in RFC 2183.

private static List<String>
tokenize(String headerValue)

public String
toString()

Overrides java.lang.Object.toString.

Return the header value for this content disposition as defined in RFC 6266.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

BASE64_ENCODED_PATTERNback to summary
private static final Pattern BASE64_ENCODED_PATTERN
charsetback to summary
private final Charset charset
Annotations
@Nullable
creationDateback to summary
private final ZonedDateTime creationDate
Annotations
@Nullable
filenameback to summary
private final String filename
Annotations
@Nullable
INVALID_HEADER_FIELD_PARAMETER_FORMATback to summary
private static final String INVALID_HEADER_FIELD_PARAMETER_FORMAT
modificationDateback to summary
private final ZonedDateTime modificationDate
Annotations
@Nullable
nameback to summary
private final String name
Annotations
@Nullable
PRINTABLEback to summary
private static final BitSet PRINTABLE
QUOTED_PRINTABLE_ENCODED_PATTERNback to summary
private static final Pattern QUOTED_PRINTABLE_ENCODED_PATTERN
readDateback to summary
private final ZonedDateTime readDate
Annotations
@Nullable
sizeback to summary
private final Long size
Annotations
@Nullable
typeback to summary
private final String type
Annotations
@Nullable

Constructor Detail

ContentDispositionback to summary
private ContentDisposition(String type, String name, String filename, Charset charset, Long size, ZonedDateTime creationDate, ZonedDateTime modificationDate, ZonedDateTime readDate)

Private constructor. See static factory methods in this class.

Method Detail

attachmentback to summary
public static ContentDisposition.Builder attachment()

Return a builder for a ContentDisposition of type "attachment".

Since
5.3
builderback to summary
public static ContentDisposition.Builder builder(String type)

Return a builder for a ContentDisposition.

Parameters
type:String

the disposition type like for example inline, attachment, or form-data

Returns:ContentDisposition.Builder

the builder

decodeQuotedPairsback to summary
private static String decodeQuotedPairs(String filename)
decodeQuotedPrintableFilenameback to summary
private static String decodeQuotedPrintableFilename(String filename, Charset charset)

Decode the given header field param as described in RFC 2047.

Parameters
filename:String

the filename

charset:Charset

the charset for the filename

Returns:String

the decoded header field param

See Also
RFC 2047
decodeRfc5987Filenameback to summary
private static String decodeRfc5987Filename(String filename, Charset charset)

Decode the given header field param as described in RFC 5987.

Only the US-ASCII, UTF-8 and ISO-8859-1 charsets are supported.

Parameters
filename:String

the filename

charset:Charset

the charset for the filename

Returns:String

the encoded header field param

See Also
RFC 5987
emptyback to summary
public static ContentDisposition empty()

Return an empty content disposition.

encodeQuotedPairsback to summary
private static String encodeQuotedPairs(String filename)
encodeQuotedPrintableFilenameback to summary
private static String encodeQuotedPrintableFilename(String filename, Charset charset)

Encode the given header field param as described in RFC 2047.

Parameters
filename:String

the filename

charset:Charset

the charset for the filename

Returns:String

the encoded header field param

See Also
RFC 2047
encodeRfc5987Filenameback to summary
private static String encodeRfc5987Filename(String input, Charset charset)

Encode the given header field param as describe in RFC 5987.

Parameters
input:String

the header field param

charset:Charset

the charset of the header field param string, only the US-ASCII, UTF-8 and ISO-8859-1 charsets are supported

Returns:String

the encoded header field param

See Also
RFC 5987
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
formDataback to summary
public static ContentDisposition.Builder formData()

Return a builder for a ContentDisposition of type "form-data".

Since
5.3
getCharsetback to summary
public Charset getCharset()

Return the charset defined in filename* parameter, or null if not defined.

Annotations
@Nullable
getCreationDateback to summary
public ZonedDateTime getCreationDate()

Deprecated

since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.

Return the value of the creation-date parameter, or null if not defined.

Annotations
@Deprecated
@Nullable
getFilenameback to summary
public String getFilename()

Return the value of the filename parameter, possibly decoded from BASE64 encoding based on RFC 2047, or of the filename* parameter, possibly decoded as defined in the RFC 5987.

Annotations
@Nullable
getModificationDateback to summary
public ZonedDateTime getModificationDate()

Deprecated

since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.

Return the value of the modification-date parameter, or null if not defined.

Annotations
@Deprecated
@Nullable
getNameback to summary
public String getName()

Return the value of the name parameter, or null if not defined.

Annotations
@Nullable
getReadDateback to summary
public ZonedDateTime getReadDate()

Deprecated

since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.

Return the value of the read-date parameter, or null if not defined.

Annotations
@Deprecated
@Nullable
getSizeback to summary
public Long getSize()

Deprecated

since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.

Return the value of the size parameter, or null if not defined.

Annotations
@Deprecated
@Nullable
getTypeback to summary
public String getType()

Return the disposition type.

Annotations
@Nullable
See Also
isAttachment(), isFormData(), isInline()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
hexDigitback to summary
private static char hexDigit(int b)
inlineback to summary
public static ContentDisposition.Builder inline()

Return a builder for a ContentDisposition of type "inline".

Since
5.3
isAttachmentback to summary
public boolean isAttachment()

Return whether the type is "attachment".

Since
5.3
isFormDataback to summary
public boolean isFormData()

Return whether the type is "form-data".

Since
5.3
isInlineback to summary
public boolean isInline()

Return whether the type is "inline".

Since
5.3
isPrintableback to summary
private static boolean isPrintable(byte c)
isRFC5987AttrCharback to summary
private static boolean isRFC5987AttrChar(byte c)
parseback to summary
public static ContentDisposition parse(String contentDisposition)

Parse a Content-Disposition header value as defined in RFC 2183.

Parameters
contentDisposition:String

the Content-Disposition header value

Returns:ContentDisposition

the parsed content disposition

See Also
toString()
tokenizeback to summary
private static List<String> tokenize(String headerValue)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return the header value for this content disposition as defined in RFC 6266.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
See Also
parse(String)
org.springframework.http back to summary

public Interface ContentDisposition.Builder

Known Direct Implementers
org.springframework.http.ContentDisposition.BuilderImpl

A mutable builder for ContentDisposition.

Method Summary

Modifier and TypeMethod and Description
public ContentDisposition
build()

Build the content disposition.

public ContentDisposition.Builder
creationDate(ZonedDateTime creationDate)

Deprecated since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.
Set the value of the creation-date parameter.
public ContentDisposition.Builder
filename(String filename)

Set the value of the filename parameter.

public ContentDisposition.Builder
filename(String filename, Charset charset)

Set the value of the filename that will be encoded as defined in RFC 5987.

public ContentDisposition.Builder
modificationDate(ZonedDateTime modificationDate)

Deprecated since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.
Set the value of the modification-date parameter.
public ContentDisposition.Builder
name(String name)

Set the value of the name parameter.

public ContentDisposition.Builder
readDate(ZonedDateTime readDate)

Deprecated since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.
Set the value of the read-date parameter.
public ContentDisposition.Builder
size(Long size)

Deprecated since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.
Set the value of the size parameter.

Method Detail

buildback to summary
public ContentDisposition build()

Build the content disposition.

creationDateback to summary
public ContentDisposition.Builder creationDate(ZonedDateTime creationDate)

Deprecated

since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.

Set the value of the creation-date parameter.

Annotations
@Deprecated
filenameback to summary
public ContentDisposition.Builder filename(String filename)

Set the value of the filename parameter. The given filename will be formatted as quoted-string, as defined in RFC 2616, section 2.2, and any quote characters within the filename value will be escaped with a backslash, e.g. "foo\"bar.txt" becomes "foo\\\"bar.txt".

filenameback to summary
public ContentDisposition.Builder filename(String filename, Charset charset)

Set the value of the filename that will be encoded as defined in RFC 5987. Only the US-ASCII, UTF-8, and ISO-8859-1 charsets are supported.

Note

Do not use this for a "multipart/form-data" request since RFC 7578, Section 4.2 and also RFC 5987 mention it does not apply to multipart requests.

modificationDateback to summary
public ContentDisposition.Builder modificationDate(ZonedDateTime modificationDate)

Deprecated

since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.

Set the value of the modification-date parameter.

Annotations
@Deprecated
nameback to summary
public ContentDisposition.Builder name(String name)

Set the value of the name parameter.

readDateback to summary
public ContentDisposition.Builder readDate(ZonedDateTime readDate)

Deprecated

since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.

Set the value of the read-date parameter.

Annotations
@Deprecated
sizeback to summary
public ContentDisposition.Builder size(Long size)

Deprecated

since 5.2.3 as per RFC 6266, Appendix B, to be removed in a future release.

Set the value of the size parameter.

Annotations
@Deprecated
org.springframework.http back to summary

private Class ContentDisposition.BuilderImpl

extends Object
implements Builder
Class Inheritance
All Implemented Interfaces
org.springframework.http.ContentDisposition.Builder

Field Summary

Modifier and TypeField and Description
private Charset
private ZonedDateTime
private String
private ZonedDateTime
private String
private ZonedDateTime
private Long
private final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ContentDisposition
build()

Implements org.springframework.http.ContentDisposition.Builder.build.

Build the content disposition.
public ContentDisposition.Builder
creationDate(ZonedDateTime creationDate)

Implements org.springframework.http.ContentDisposition.Builder.creationDate.

Set the value of the creation-date parameter.
public ContentDisposition.Builder
filename(String filename)

Implements org.springframework.http.ContentDisposition.Builder.filename.

Set the value of the filename parameter.
public ContentDisposition.Builder
filename(String filename, Charset charset)

Implements org.springframework.http.ContentDisposition.Builder.filename.

Set the value of the filename that will be encoded as defined in RFC 5987.
public ContentDisposition.Builder
modificationDate(ZonedDateTime modificationDate)

Implements org.springframework.http.ContentDisposition.Builder.modificationDate.

Set the value of the modification-date parameter.
public ContentDisposition.Builder
name(String name)

Implements org.springframework.http.ContentDisposition.Builder.name.

Set the value of the name parameter.
public ContentDisposition.Builder
readDate(ZonedDateTime readDate)

Implements org.springframework.http.ContentDisposition.Builder.readDate.

Set the value of the read-date parameter.
public ContentDisposition.Builder
size(Long size)

Implements org.springframework.http.ContentDisposition.Builder.size.

Set the value of the size parameter.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

charsetback to summary
private Charset charset
Annotations
@Nullable
creationDateback to summary
private ZonedDateTime creationDate
Annotations
@Nullable
filenameback to summary
private String filename
Annotations
@Nullable
modificationDateback to summary
private ZonedDateTime modificationDate
Annotations
@Nullable
nameback to summary
private String name
Annotations
@Nullable
readDateback to summary
private ZonedDateTime readDate
Annotations
@Nullable
sizeback to summary
private Long size
Annotations
@Nullable
typeback to summary
private final String type

Constructor Detail

BuilderImplback to summary
public BuilderImpl(String type)

Method Detail

buildback to summary
public ContentDisposition build()

Implements org.springframework.http.ContentDisposition.Builder.build.

Doc from org.springframework.http.ContentDisposition.Builder.build.

Build the content disposition.

Annotations
@Override
creationDateback to summary
public ContentDisposition.Builder creationDate(ZonedDateTime creationDate)

Implements org.springframework.http.ContentDisposition.Builder.creationDate.

Doc from org.springframework.http.ContentDisposition.Builder.creationDate.

Set the value of the creation-date parameter.

Annotations
@Override
@SuppressWarnings:deprecation
filenameback to summary
public ContentDisposition.Builder filename(String filename)

Implements org.springframework.http.ContentDisposition.Builder.filename.

Doc from org.springframework.http.ContentDisposition.Builder.filename.

Set the value of the filename parameter. The given filename will be formatted as quoted-string, as defined in RFC 2616, section 2.2, and any quote characters within the filename value will be escaped with a backslash, e.g. "foo\"bar.txt" becomes "foo\\\"bar.txt".

Annotations
@Override
filenameback to summary
public ContentDisposition.Builder filename(String filename, Charset charset)

Implements org.springframework.http.ContentDisposition.Builder.filename.

Doc from org.springframework.http.ContentDisposition.Builder.filename.

Set the value of the filename that will be encoded as defined in RFC 5987. Only the US-ASCII, UTF-8, and ISO-8859-1 charsets are supported.

Note

Do not use this for a "multipart/form-data" request since RFC 7578, Section 4.2 and also RFC 5987 mention it does not apply to multipart requests.

Annotations
@Override
modificationDateback to summary
public ContentDisposition.Builder modificationDate(ZonedDateTime modificationDate)

Implements org.springframework.http.ContentDisposition.Builder.modificationDate.

Doc from org.springframework.http.ContentDisposition.Builder.modificationDate.

Set the value of the modification-date parameter.

Annotations
@Override
@SuppressWarnings:deprecation
nameback to summary
public ContentDisposition.Builder name(String name)

Implements org.springframework.http.ContentDisposition.Builder.name.

Doc from org.springframework.http.ContentDisposition.Builder.name.

Set the value of the name parameter.

Annotations
@Override
readDateback to summary
public ContentDisposition.Builder readDate(ZonedDateTime readDate)

Implements org.springframework.http.ContentDisposition.Builder.readDate.

Doc from org.springframework.http.ContentDisposition.Builder.readDate.

Set the value of the read-date parameter.

Annotations
@Override
@SuppressWarnings:deprecation
sizeback to summary
public ContentDisposition.Builder size(Long size)

Implements org.springframework.http.ContentDisposition.Builder.size.

Doc from org.springframework.http.ContentDisposition.Builder.size.

Set the value of the size parameter.

Annotations
@Override
@SuppressWarnings:deprecation