Class MultipartBodyPublisher.Builder
java.lang.Object
com.github.mizosoft.methanol.MultipartBodyPublisher.Builder
- Enclosing class:
MultipartBodyPublisher
A builder of
MultipartBodyPublisher instances. The default multipart subtype used by
the builder is form-data.
Any part added with a MimeBodyPublisher will have it's Content-Type header
automatically appended to the part's headers during transmission.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets the boundary of the multipart body.build()Returns a newMultipartBodyPublisher.Adds a file form field with the given name and file.Adds a file form field with given name, file and media type.formPart(String name, String filename, HttpRequest.BodyPublisher bodyPublisher) Adds a form field with the given name, filename and body.formPart(String name, String filename, HttpRequest.BodyPublisher bodyPublisher, MediaType mediaType) Adds a form field with the given name, filename, body and media type.formPart(String name, HttpRequest.BodyPublisher bodyPublisher) Adds a form field with the given name and body.Sets the media type of the multipart body.Adds the given part.Adds atext/plainform field with the given name and value.Adds atext/plainform field with the given name and value, using the given charset for encoding the field's value.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
boundary
Sets the boundary of the multipart body.- Throws:
IllegalArgumentException- if the boundary is invalid
-
mediaType
Sets the media type of the multipart body. If the given media type has a boundary parameter, it will be used as the body's boundary.- Throws:
IllegalArgumentException- if the given media type is not a multipart type or if it has an invalid boundary parameter
-
part
Adds the given part. -
formPart
@CanIgnoreReturnValue public MultipartBodyPublisher.Builder formPart(String name, HttpRequest.BodyPublisher bodyPublisher) Adds a form field with the given name and body. -
formPart
@CanIgnoreReturnValue public MultipartBodyPublisher.Builder formPart(String name, String filename, HttpRequest.BodyPublisher bodyPublisher) Adds a form field with the given name, filename and body. -
formPart
@CanIgnoreReturnValue public MultipartBodyPublisher.Builder formPart(String name, String filename, HttpRequest.BodyPublisher bodyPublisher, MediaType mediaType) Adds a form field with the given name, filename, body and media type. -
textPart
Adds atext/plainform field with the given name and value.UTF-8is used for encoding the field's body. -
textPart
@CanIgnoreReturnValue public MultipartBodyPublisher.Builder textPart(String name, Object value, Charset charset) Adds atext/plainform field with the given name and value, using the given charset for encoding the field's value. -
filePart
@CanIgnoreReturnValue public MultipartBodyPublisher.Builder filePart(String name, Path file) throws FileNotFoundException Adds a file form field with the given name and file. The field's filename property will be that of the given path'sfilename component. The given path will be used toprobethe part's media type. If probing fails, either by throwing an exception or returningnull,application/octet-streamwill be used.- Throws:
FileNotFoundException- if a file with the given path cannot be found
-
filePart
@CanIgnoreReturnValue public MultipartBodyPublisher.Builder filePart(String name, Path file, MediaType mediaType) throws FileNotFoundException Adds a file form field with given name, file and media type. The field's filename property will be that of the given path'sfilename compontent.- Throws:
FileNotFoundException- if a file with the given path cannot be found
-
build
Returns a newMultipartBodyPublisher. If no boundary has been set, a randomly generated one is used.- Throws:
IllegalStateException- if no part was added
-