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 a HttpRequest.BodyPublisher to represent the data. Intended for use with Java 11+ HttpClient.
Since:
8.5.0
  • Constructor Details

    • 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 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

      @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

      Builds the final multipart BodyPublisher.

      This publisher streams binary parts and concatenates everything lazily. Does not buffer the entire multipart body in memory.