Class HeaderValueFormatter


  • public class HeaderValueFormatter
    extends Object
    Basic implementation for formatting header value elements. Instances of this class are stateless and thread-safe. Derived classes are expected to maintain these properties.
    Since:
    4.0
    • Field Detail

      • SEPARATORS

        public static final String SEPARATORS
        Special characters that can be used as separators in HTTP parameters. These special characters MUST be in a quoted string to be used within a parameter value .
        See Also:
        Constant Field Values
      • UNSAFE_CHARS

        public static final String UNSAFE_CHARS
        Unsafe special characters that must be escaped using the backslash character
        See Also:
        Constant Field Values
    • Constructor Detail

      • HeaderValueFormatter

        public HeaderValueFormatter()
    • Method Detail

      • formatParameters

        public static String formatParameters​(NameValue[] nvps,
                                              boolean quote,
                                              HeaderValueFormatter formatter)
        Formats a set of parameters.
        Parameters:
        nvps - the parameters to format
        quote - true to always format with quoted values, false to use quotes only when necessary
        formatter - the formatter to use, or null for the default
        Returns:
        the formatted parameters
      • estimateParametersLen

        protected int estimateParametersLen​(NameValue[] nvps)
        Estimates the length of formatted parameters.
        Parameters:
        nvps - the parameters to format, or null
        Returns:
        a length estimate, in number of characters
      • formatNameValuePair

        public static String formatNameValuePair​(NameValue nvp,
                                                 boolean quote,
                                                 HeaderValueFormatter formatter)
        Formats a name-value pair.
        Parameters:
        nvp - the name-value pair to format
        quote - true to always format with a quoted value, false to use quotes only when necessary
        formatter - the formatter to use, or null for the default
        Returns:
        the formatted name-value pair
      • estimateNameValuePairLen

        protected int estimateNameValuePairLen​(NameValue nvp)
        Estimates the length of a formatted name-value pair.
        Parameters:
        nvp - the name-value pair to format, or null
        Returns:
        a length estimate, in number of characters
      • doFormatValue

        protected void doFormatValue​(CharArrayBuffer buffer,
                                     String value,
                                     boolean quote)
        Actually formats the value of a name-value pair. This does not include a leading = character. Called from formatNameValuePair.
        Parameters:
        buffer - the buffer to append to, never null
        value - the value to append, never null
        quote - true to always format with quotes, false to use quotes only when necessary
      • isSeparator

        protected boolean isSeparator​(char ch)
        Checks whether a character is a separator.
        Parameters:
        ch - the character to check
        Returns:
        true if the character is a separator, false otherwise
      • isUnsafe

        protected boolean isUnsafe​(char ch)
        Checks whether a character is unsafe.
        Parameters:
        ch - the character to check
        Returns:
        true if the character is unsafe, false otherwise