Interface EntityPart.Builder
-
- Enclosing interface:
- EntityPart
public static interface EntityPart.Builder
Builder forEntityPart
instances.- Since:
- 3.1
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description EntityPart
build()
Builds a new EntityPart instance using the provided property values.EntityPart.Builder
content(InputStream content)
Sets the content for this part.default EntityPart.Builder
content(Object content)
Sets the content for this part.default EntityPart.Builder
content(String fileName, InputStream content)
Convenience method, equivalent to callingfileName(fileName).content(content)
.<T> EntityPart.Builder
content(T content, GenericType<T> type)
Sets the content for this part.<T> EntityPart.Builder
content(T content, Class<? extends T> type)
Sets the content for this part.EntityPart.Builder
fileName(String fileName)
Sets the file name for this part.EntityPart.Builder
header(String headerName, String... headerValues)
Adds a new header or replaces a previously added header and sets the header value(s).EntityPart.Builder
headers(MultivaluedMap<String,String> newHeaders)
Adds new headers or replaces previously added headers.EntityPart.Builder
mediaType(MediaType mediaType)
Sets the media type for the EntityPart.EntityPart.Builder
mediaType(String mediaTypeString)
Convenience method for setting the media type for the EntityPart.
-
-
-
Method Detail
-
mediaType
EntityPart.Builder mediaType(MediaType mediaType) throws IllegalArgumentException
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
EntityPart.Builder mediaType(String mediaTypeString) throws IllegalArgumentException
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 IllegalArgumentException
Adds 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
EntityPart.Builder fileName(String fileName) throws IllegalArgumentException
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
EntityPart.Builder content(InputStream content) throws IllegalArgumentException
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
<T> EntityPart.Builder content(T content, Class<? extends T> type) throws IllegalArgumentException
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
default EntityPart.Builder content(Object content) throws IllegalArgumentException
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
<T> EntityPart.Builder content(T content, GenericType<T> type) throws IllegalArgumentException
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
EntityPart build() throws IllegalStateException, IOException, WebApplicationException
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
-
-