Interface EntityPart.Builder
-
- Enclosing interface:
- EntityPart
public static interface EntityPart.BuilderBuilder forEntityPartinstances.- Since:
- 3.1
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description EntityPartbuild()Builds a new EntityPart instance using the provided property values.EntityPart.Buildercontent(InputStream content)Sets the content for this part.default EntityPart.Buildercontent(Object content)Sets the content for this part.default EntityPart.Buildercontent(String fileName, InputStream content)Convenience method, equivalent to callingfileName(fileName).content(content).<T> EntityPart.Buildercontent(T content, GenericType<T> type)Sets the content for this part.<T> EntityPart.Buildercontent(T content, Class<? extends T> type)Sets the content for this part.EntityPart.BuilderfileName(String fileName)Sets the file name for this part.EntityPart.Builderheader(String headerName, String... headerValues)Adds a new header or replaces a previously added header and sets the header value(s).EntityPart.Builderheaders(MultivaluedMap<String,String> newHeaders)Adds new headers or replaces previously added headers.EntityPart.BuildermediaType(MediaType mediaType)Sets the media type for the EntityPart.EntityPart.BuildermediaType(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-Typeheader for this part.- Parameters:
mediaType- the media type for the part to be built- Returns:
- the updated builder
- Throws:
IllegalArgumentException- ifmediaTypeisnull
-
mediaType
EntityPart.Builder mediaType(String mediaTypeString) throws IllegalArgumentException
Convenience method for setting the media type for the EntityPart. This will also set theContent-Typeheader 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- ifmediaTypeStringcannot 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- ifheaderNameisnull
-
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- ifnewHeadersisnull
-
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-Dispositionheader 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- iffileNameisnull
-
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
InputStreamwill 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-InputStreamof the content of this part- Returns:
- the updated builder
- Throws:
IllegalArgumentException- ifcontentisnull
-
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 registeredMessageBodyWriterthat is capable of writing the object type specified here using the defaultMediaTypeor theMediaTypespecified 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- ifcontentisnull
-
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 registeredMessageBodyWriterthat is capable of writing the object's class type specified here using the defaultMediaTypeor theMediaTypespecified 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- ifcontentisnull
-
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 registeredMessageBodyWriterthat is capable of writing the object type specified here using the defaultMediaTypeor theMediaTypespecified 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- ifcontentisnull
-
build
EntityPart build() throws IllegalStateException, IOException, WebApplicationException
Builds a new EntityPart instance using the provided property values.- Returns:
EntityPartinstance built from the provided property values.- Throws:
IllegalStateException- if the content was not specified or no matchingMessageBodyWriterwas found.IOException- if the underlyingMessageBodyWriterthrows anIOExceptionWebApplicationException- if the underlyingMessageBodyWriterthrows aWebApplicationException
-
-