- java.lang.Object
-
- com.github.mizosoft.methanol.MultipartBodyPublisher.Builder
-
- Enclosing class:
- MultipartBodyPublisher
public static final class MultipartBodyPublisher.Builder extends java.lang.ObjectA builder ofMultipartBodyPublisherinstances. The default multipart subtype used by the builder isform-data.Any part added with a
MimeBodyPublisherwill have it'sContent-Typeheader automatically appended to the part's headers during transmission.
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MultipartBodyPublisher.Builderboundary(java.lang.String boundary)Sets the boundary of the multipart body.MultipartBodyPublisherbuild()Returns a newMultipartBodyPublisher.MultipartBodyPublisher.BuilderfilePart(java.lang.String name, java.nio.file.Path file)Adds a file form field with the given name and file.MultipartBodyPublisher.BuilderfilePart(java.lang.String name, java.nio.file.Path file, MediaType mediaType)Adds a file form field with given name, file and media type.MultipartBodyPublisher.BuilderformPart(java.lang.String name, java.lang.String filename, java.net.http.HttpRequest.BodyPublisher bodyPublisher)Adds a form field with the given name, filename and body.MultipartBodyPublisher.BuilderformPart(java.lang.String name, java.lang.String filename, java.net.http.HttpRequest.BodyPublisher bodyPublisher, MediaType mediaType)Adds a form field with the given name, filename, body and media type.MultipartBodyPublisher.BuilderformPart(java.lang.String name, java.net.http.HttpRequest.BodyPublisher bodyPublisher)Adds a form field with the given name and body.MultipartBodyPublisher.BuildermediaType(MediaType mediaType)Sets the media type of the multipart body.MultipartBodyPublisher.Builderpart(MultipartBodyPublisher.Part part)Adds the given part.MultipartBodyPublisher.BuildertextPart(java.lang.String name, java.lang.Object value)Adds atext/plainform field with the given name and value.MultipartBodyPublisher.BuildertextPart(java.lang.String name, java.lang.Object value, java.nio.charset.Charset charset)Adds atext/plainform field with the given name and value, using the given charset for encoding the field's value.
-
-
-
Method Detail
-
boundary
@CanIgnoreReturnValue public MultipartBodyPublisher.Builder boundary(java.lang.String boundary)
Sets the boundary of the multipart body.- Throws:
java.lang.IllegalArgumentException- if the boundary is invalid
-
mediaType
@CanIgnoreReturnValue public MultipartBodyPublisher.Builder mediaType(MediaType 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:
java.lang.IllegalArgumentException- if the given media type is not a multipart type or if it has an invalid boundary parameter
-
part
@CanIgnoreReturnValue public MultipartBodyPublisher.Builder part(MultipartBodyPublisher.Part part)
Adds the given part.
-
formPart
@CanIgnoreReturnValue public MultipartBodyPublisher.Builder formPart(java.lang.String name, java.net.http.HttpRequest.BodyPublisher bodyPublisher)
Adds a form field with the given name and body.
-
formPart
@CanIgnoreReturnValue public MultipartBodyPublisher.Builder formPart(java.lang.String name, java.lang.String filename, java.net.http.HttpRequest.BodyPublisher bodyPublisher)
Adds a form field with the given name, filename and body.
-
formPart
@CanIgnoreReturnValue public MultipartBodyPublisher.Builder formPart(java.lang.String name, java.lang.String filename, java.net.http.HttpRequest.BodyPublisher bodyPublisher, MediaType mediaType)
Adds a form field with the given name, filename, body and media type.
-
textPart
@CanIgnoreReturnValue public MultipartBodyPublisher.Builder textPart(java.lang.String name, java.lang.Object value)
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(java.lang.String name, java.lang.Object value, java.nio.charset.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(java.lang.String name, java.nio.file.Path file) throws java.io.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:
java.io.FileNotFoundException- if a file with the given path cannot be found
-
filePart
@CanIgnoreReturnValue public MultipartBodyPublisher.Builder filePart(java.lang.String name, java.nio.file.Path file, MediaType mediaType) throws java.io.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:
java.io.FileNotFoundException- if a file with the given path cannot be found
-
build
public MultipartBodyPublisher build()
Returns a newMultipartBodyPublisher. If no boundary has been set, a randomly generated one is used.- Throws:
java.lang.IllegalStateException- if no part was added
-
-