Class FormBodyPartBuilder


  • public class FormBodyPartBuilder
    extends java.lang.Object
    Builder for individual FormBodyParts.
    Since:
    4.4
    • Field Detail

      • name

        private java.lang.String name
      • header

        private final Header header
      • iso8859_1Encoder

        private java.nio.charset.CharsetEncoder iso8859_1Encoder
        Encoder used to check if strings can be encoded in ISO-8859-1, supporting filename compatibility determinations in multipart form data.
    • Constructor Detail

      • FormBodyPartBuilder

        FormBodyPartBuilder()
    • Method Detail

      • create

        public static FormBodyPartBuilder create​(java.lang.String name,
                                                 ContentBody body,
                                                 HttpMultipartMode mode)
        Creates a new builder instance with the specified name, content body, and multipart mode.
        Parameters:
        name - the name of the form field
        body - the content body of the part
        mode - the HttpMultipartMode to use, determining filename encoding behavior;
        Returns:
        a new FormBodyPartBuilder instance
        Since:
        5.5
      • addField

        public FormBodyPartBuilder addField​(java.lang.String name,
                                            java.lang.String value,
                                            java.util.List<org.apache.hc.core5.http.NameValuePair> parameters)
        Since:
        4.6
      • addField

        public FormBodyPartBuilder addField​(java.lang.String name,
                                            java.lang.String value)
      • setField

        public FormBodyPartBuilder setField​(java.lang.String name,
                                            java.lang.String value)
      • canEncodeToISO8859_1

        private boolean canEncodeToISO8859_1​(java.lang.String input)
        Determines whether the given string can be encoded in ISO-8859-1 without loss of data. This is used to decide whether the filename parameter can be used as-is or if the filename* parameter is needed for non-ISO-8859-1 characters.
        Parameters:
        input - the string to check, must not be null
        Returns:
        true if the string can be encoded in ISO-8859-1, false otherwise
        Since:
        5.5
      • encodeRFC5987

        private static java.lang.String encodeRFC5987​(java.lang.String filename)
        Encodes the given filename according to RFC 5987, prefixing it with UTF-8'' and applying percent-encoding to non-ASCII characters. This is used for the filename* parameter in the Content-Disposition header when non-ISO-8859-1 characters are present.
        Parameters:
        filename - the filename to encode, must not be null
        Returns:
        the RFC 5987-encoded string, e.g., UTF-8''example%20text
        Since:
        5.5