Class BodyPublisherMultipartBodyBuilder
java.lang.Object
de.xima.fc.web.common.multipart.BodyPublisherMultipartBodyBuilder
Builder for a multipart body that uses a
HttpRequest.BodyPublisher to represent the data. Intended for use with Java 11+
HttpClient.- Since:
- 8.5.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new multipart builder with a random boundary.BodyPublisherMultipartBodyBuilder(String boundary) Creates a new multipart builder with the given boundary. -
Method Summary
Modifier and TypeMethodDescriptionaddBinary(String name, BinaryMultipartContent<IInputStreamSupplier> content) Adds a file upload part to the list of parts.addBinary(String name, String fileName, String contentType, long contentLength, IInputStreamSupplier data) Adds a file upload part to the list of parts.Adds a simple text form field part.boundary()Gets the boundary string used to separate parts.build()Builds the final multipart BodyPublisher.
-
Constructor Details
-
BodyPublisherMultipartBodyBuilder
public BodyPublisherMultipartBodyBuilder()Creates a new multipart builder with a random boundary. -
BodyPublisherMultipartBodyBuilder
Creates a new multipart builder with the given boundary.- Parameters:
boundary- The boundary string to use.
-
-
Method Details
-
addBinary
@CanIgnoreReturnValue public BodyPublisherMultipartBodyBuilder addBinary(String name, BinaryMultipartContent<IInputStreamSupplier> content) Adds a file upload part to the list of parts.- Parameters:
name- The name of the form field.content- The binary multipart content.
-
addBinary
@CanIgnoreReturnValue public BodyPublisherMultipartBodyBuilder addBinary(String name, String fileName, String contentType, long contentLength, IInputStreamSupplier data) Adds a file upload part to the list of parts.- Parameters:
name- The name of the form field.fileName- The filename to report in the Content-Disposition header.contentType- The content type of the file.data- The InputStream supplier for the file data.
-
addText
Adds a simple text form field part.- Parameters:
name- The name of the form field.value- The value of the form field.- Returns:
- This builder for method chaining.
-
boundary
Gets the boundary string used to separate parts.- Returns:
- The boundary string.
-
build
Builds the final multipart BodyPublisher.This publisher streams binary parts and concatenates everything lazily. Does not buffer the entire multipart body in memory.
-