Package de.xima.fc.web.common.multipart
Class BodyPublisherMultipartBodyBuilder
- java.lang.Object
-
- de.xima.fc.web.common.multipart.BodyPublisherMultipartBodyBuilder
-
public final class BodyPublisherMultipartBodyBuilder extends Object
Builder for a multipart body that uses aHttpRequest.BodyPublisherto represent the data. Intended for use with Java 11+HttpClient.- Since:
- 8.5.0
-
-
Constructor Summary
Constructors Constructor Description BodyPublisherMultipartBodyBuilder()Creates a new multipart builder with a random boundary.BodyPublisherMultipartBodyBuilder(String boundary)Creates a new multipart builder with the given boundary.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BodyPublisherMultipartBodyBuilderaddBinary(String name, BinaryMultipartContent<IInputStreamSupplier> content)Adds a file upload part to the list of parts.BodyPublisherMultipartBodyBuilderaddBinary(String name, String fileName, String contentType, long contentLength, IInputStreamSupplier data)Adds a file upload part to the list of parts.BodyPublisherMultipartBodyBuilderaddText(String name, String value)Adds a simple text form field part.Stringboundary()Gets the boundary string used to separate parts.IMultipartBody<HttpRequest.BodyPublisher>build()Builds the final multipart BodyPublisher.
-
-
-
Constructor Detail
-
BodyPublisherMultipartBodyBuilder
public BodyPublisherMultipartBodyBuilder()
Creates a new multipart builder with a random boundary.
-
BodyPublisherMultipartBodyBuilder
public BodyPublisherMultipartBodyBuilder(String boundary)
Creates a new multipart builder with the given boundary.- Parameters:
boundary- The boundary string to use.
-
-
Method Detail
-
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
@CanIgnoreReturnValue public BodyPublisherMultipartBodyBuilder addText(String name, String value)
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
public String boundary()
Gets the boundary string used to separate parts.- Returns:
- The boundary string.
-
build
public IMultipartBody<HttpRequest.BodyPublisher> build()
Builds the final multipart BodyPublisher.This publisher streams binary parts and concatenates everything lazily. Does not buffer the entire multipart body in memory.
-
-