Interface EntityPart.Builder
- Enclosing interface:
EntityPart
EntityPart
instances.- Since:
- 3.1
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds a new EntityPart instance using the provided property values.content
(InputStream content) Sets the content for this part.default EntityPart.Builder
Sets the content for this part.default EntityPart.Builder
content
(String fileName, InputStream content) Convenience method, equivalent to callingfileName(fileName).content(content)
.content
(T content, GenericType<T> type) Sets the content for this part.Sets the content for this part.Sets the file name for this part.Adds a new header or replaces a previously added header and sets the header value(s).headers
(MultivaluedMap<String, String> newHeaders) Adds new headers or replaces previously added headers.Sets the media type for the EntityPart.Convenience method for setting the media type for the EntityPart.
-
Method Details
-
mediaType
Sets the media type for the EntityPart. This will also set theContent-Type
header for this part.- Parameters:
mediaType
- the media type for the part to be built- Returns:
- the updated builder
- Throws:
IllegalArgumentException
- ifmediaType
isnull
-
mediaType
Convenience method for setting the media type for the EntityPart. This will also set theContent-Type
header for this part. This call is effectively the same asmediaType(MediaType.valueOf(mediaTypeString))
.- Parameters:
mediaTypeString
- the media type for the part to be built- Returns:
- the updated builder
- Throws:
IllegalArgumentException
- ifmediaTypeString
cannot be parsed or isnull
-
header
EntityPart.Builder header(String headerName, String... headerValues) throws IllegalArgumentException Adds a new header or replaces a previously added header and sets the header value(s).- Parameters:
headerName
- the header nameheaderValues
- the header value(s)- Returns:
- the updated builder
- Throws:
IllegalArgumentException
- ifheaderName
isnull
-
headers
EntityPart.Builder headers(MultivaluedMap<String, String> newHeaders) throws IllegalArgumentExceptionAdds new headers or replaces previously added headers. The behavior of this method would be the same as if iterating over the entry set and invoking theheader(String, String...)
method.- Parameters:
newHeaders
- the multivalued map of headers to add to this part- Returns:
- the updated builder
- Throws:
IllegalArgumentException
- ifnewHeaders
isnull
-
fileName
Sets the file name for this part. The file name will be specified as an attribute in theContent-Disposition
header of this part. When this method is called, the default media type used for the built part will be "application/octet-stream" if not otherwise specified.- Parameters:
fileName
- the file name for this part- Returns:
- the updated builder
- Throws:
IllegalArgumentException
- iffileName
isnull
-
content
Sets the content for this part. The content of this builder must be specified before invoking thebuild()
method.The
InputStream
will be closed by the implementation code after sending the multipart data. Closing the stream before it is sent could result in unexpected behavior.- Parameters:
content
-InputStream
of the content of this part- Returns:
- the updated builder
- Throws:
IllegalArgumentException
- ifcontent
isnull
-
content
default EntityPart.Builder content(String fileName, InputStream content) throws IllegalArgumentException Convenience method, equivalent to callingfileName(fileName).content(content)
.- Parameters:
fileName
- the filename of the part.content
- the content stream of the part.- Returns:
- the updated builder.
- Throws:
IllegalArgumentException
- if either parameter isnull
.
-
content
Sets the content for this part. The content of this builder must be specified before invoking thebuild()
method.If the content is specified using this method, then the
build()
method is responsible for finding a registeredMessageBodyWriter
that is capable of writing the object type specified here using the defaultMediaType
or theMediaType
specified in themediaType(MediaType)
ormediaType(String)
methods and using any headers specified via theheader(String, String...)
orheaders(MultivaluedMap)
methods.- Type Parameters:
T
- the entity type- Parameters:
content
- the object to be used as the contenttype
- the type of this object which will be used when selecting the appropriateMessageBodyWriter
- Returns:
- the updated builder.
- Throws:
IllegalArgumentException
- ifcontent
isnull
-
content
Sets the content for this part. The content of this builder must be specified before invoking thebuild()
method.If the content is specified using this method, then the
build()
method is responsible for finding a registeredMessageBodyWriter
that is capable of writing the object's class type specified here using the defaultMediaType
or theMediaType
specified in themediaType(MediaType)
ormediaType(String)
methods and using any headers specified via theheader(String, String...)
orheaders(MultivaluedMap)
methods.This is the equivalent of calling
content(content, content.getClass())
.- Parameters:
content
- the object to be used as the content- Returns:
- the updated builder.
- Throws:
IllegalArgumentException
- ifcontent
isnull
-
content
Sets the content for this part. The content of this builder must be specified before invoking thebuild()
method.If the content is specified using this method, then the
build()
method is responsible for finding a registeredMessageBodyWriter
that is capable of writing the object type specified here using the defaultMediaType
or theMediaType
specified in themediaType(MediaType)
ormediaType(String)
methods and using any headers specified via theheader(String, String...)
orheaders(MultivaluedMap)
methods.- Type Parameters:
T
- the entity type- Parameters:
content
- the object to be used as the contenttype
- the generic type of this object which will be used when selecting the appropriateMessageBodyWriter
- Returns:
- the updated builder.
- Throws:
IllegalArgumentException
- ifcontent
isnull
-
build
Builds a new EntityPart instance using the provided property values.- Returns:
EntityPart
instance built from the provided property values.- Throws:
IllegalStateException
- if the content was not specified or no matchingMessageBodyWriter
was found.IOException
- if the underlyingMessageBodyWriter
throws anIOException
WebApplicationException
- if the underlyingMessageBodyWriter
throws aWebApplicationException
-