Class MultipartBodyPublisher.Builder

  • Enclosing class:
    MultipartBodyPublisher

    static final class MultipartBodyPublisher.Builder
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<Part> parts  
    • Constructor Summary

      Constructors 
      Constructor Description
      Builder()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) MultipartBodyPublisher build​(ProgressMonitor monitor)
      Creates and returns a new MultipartBodyPublisher with a snapshot of the added parts.
      (package private) MultipartBodyPublisher.Builder filePart​(java.lang.String name, java.nio.file.Path file, java.lang.String mediaType)
      Adds a file form field with given name, file and media type.
      (package private) MultipartBodyPublisher.Builder formPart​(java.lang.String name, java.lang.String filename, java.net.http.HttpRequest.BodyPublisher body)
      Adds a form field with the given name, filename and body.
      (package private) MultipartBodyPublisher.Builder formPart​(java.lang.String name, java.net.http.HttpRequest.BodyPublisher bodyPublisher)
      Adds a form field with the given name and body.
      (package private) MultipartBodyPublisher.Builder textPart​(java.lang.String name, java.lang.Object value)
      Adds a text/plain form field with the given name and value.
      (package private) MultipartBodyPublisher.Builder textPart​(java.lang.String name, java.lang.Object value, java.nio.charset.Charset charset)
      Adds a text/plain form field with the given name and value using the given charset for encoding the field's body.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • parts

        private final java.util.List<Part> parts
    • Constructor Detail

      • Builder

        Builder()
    • Method Detail

      • formPart

        MultipartBodyPublisher.Builder formPart​(java.lang.String name,
                                                java.net.http.HttpRequest.BodyPublisher bodyPublisher)
        Adds a form field with the given name and body.
        Parameters:
        name - the field's name
        bodyPublisher - the field's body publisher
      • formPart

        MultipartBodyPublisher.Builder formPart​(java.lang.String name,
                                                java.lang.String filename,
                                                java.net.http.HttpRequest.BodyPublisher body)
        Adds a form field with the given name, filename and body.
        Parameters:
        name - the field's name
        filename - the field's filename
        body - the field's body publisher
      • textPart

        MultipartBodyPublisher.Builder textPart​(java.lang.String name,
                                                java.lang.Object value)
        Adds a text/plain form field with the given name and value. UTF-8 is used for encoding the field's body.
        Parameters:
        name - the field's name
        value - an object whose string representation is used as the value
      • textPart

        MultipartBodyPublisher.Builder textPart​(java.lang.String name,
                                                java.lang.Object value,
                                                java.nio.charset.Charset charset)
        Adds a text/plain form field with the given name and value using the given charset for encoding the field's body.
        Parameters:
        name - the field's name
        value - an object whose string representation is used as the value
        charset - the charset for encoding the field's body
      • filePart

        MultipartBodyPublisher.Builder filePart​(java.lang.String name,
                                                java.nio.file.Path file,
                                                java.lang.String 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's filename compontent.
        Parameters:
        name - the field's name
        file - the file's path
        mediaType - the part's media type
        Throws:
        java.io.FileNotFoundException - if a file with the given path cannot be found
      • build

        MultipartBodyPublisher build​(ProgressMonitor monitor)
        Creates and returns a new MultipartBodyPublisher with a snapshot of the added parts. If no boundary was previously set, a randomly generated one is used.
        Throws:
        java.lang.IllegalStateException - if no part was added