Class Parameters


  • public final class Parameters
    extends java.lang.Object
    Utility class for parsing and managing HTTP parameters.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Parameters.FailReason  
    • Constructor Summary

      Constructors 
      Constructor Description
      Parameters()
      Construct a new Parameters instance with default settings.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addParameter​(java.lang.String key, java.lang.String value)
      Add a parameter with the given key and value.
      java.nio.charset.Charset getCharset()
      Returns the character set used for decoding body parameters.
      java.lang.String getParameter​(java.lang.String name)
      Returns the first value of the parameter with the given name.
      java.util.Enumeration<java.lang.String> getParameterNames()
      Returns the names of all parameters.
      java.lang.String[] getParameterValues​(java.lang.String name)
      Returns the values of the parameter with the given name.
      Parameters.FailReason getParseFailedReason()  
      void handleQueryParameters()
      Process the query string into parameters
      boolean isParseFailed()  
      void processParameters​(byte[] bytes, int start, int len)
      Process the given byte array as a set of URL-encoded parameters using the current character set.
      void processParameters​(MessageBytes data, java.nio.charset.Charset charset)
      Process the given MessageBytes as a set of URL-encoded parameters using the specified character set.
      void recycle()
      Reset this object so it can be reused for a new request.
      void setCharset​(java.nio.charset.Charset charset)
      Set the character set used for decoding body parameters.
      void setLimit​(int limit)
      Set the maximum number of parameters allowed.
      void setParseFailedReason​(Parameters.FailReason failReason)  
      void setQuery​(MessageBytes queryMB)
      Set the query string to be parsed into parameters.
      void setQueryStringCharset​(java.nio.charset.Charset queryStringCharset)
      Set the character set used for decoding query string parameters.
      void setURLDecoder​(UDecoder u)
      Set the URL decoder to use for decoding parameter names and values.
      int size()
      Returns the number of parameters that have been parsed.
      java.lang.String toString()
      Debug purpose
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Parameters

        public Parameters()
        Construct a new Parameters instance with default settings.
    • Method Detail

      • setQuery

        public void setQuery​(MessageBytes queryMB)
        Set the query string to be parsed into parameters.
        Parameters:
        queryMB - The query string as a MessageBytes object
      • setLimit

        public void setLimit​(int limit)
        Set the maximum number of parameters allowed.
        Parameters:
        limit - The maximum number of parameters, or -1 for no limit
      • getCharset

        public java.nio.charset.Charset getCharset()
        Returns the character set used for decoding body parameters.
        Returns:
        the character set
      • setCharset

        public void setCharset​(java.nio.charset.Charset charset)
        Set the character set used for decoding body parameters.
        Parameters:
        charset - The character set, or null to use the default (ISO-8859-1)
      • setQueryStringCharset

        public void setQueryStringCharset​(java.nio.charset.Charset queryStringCharset)
        Set the character set used for decoding query string parameters.
        Parameters:
        queryStringCharset - The character set, or null to use the default (UTF-8)
      • isParseFailed

        public boolean isParseFailed()
      • size

        public int size()
        Returns the number of parameters that have been parsed.
        Returns:
        the number of parameters
      • recycle

        public void recycle()
        Reset this object so it can be reused for a new request.
      • getParameterValues

        public java.lang.String[] getParameterValues​(java.lang.String name)
        Returns the values of the parameter with the given name.
        Parameters:
        name - The name of the parameter
        Returns:
        The values of the parameter, or null if the parameter does not exist
      • getParameterNames

        public java.util.Enumeration<java.lang.String> getParameterNames()
        Returns the names of all parameters.
        Returns:
        An enumeration of parameter names
      • getParameter

        public java.lang.String getParameter​(java.lang.String name)
        Returns the first value of the parameter with the given name.
        Parameters:
        name - The name of the parameter
        Returns:
        The first value of the parameter, or null if the parameter does not exist
      • handleQueryParameters

        public void handleQueryParameters()
        Process the query string into parameters
      • addParameter

        public void addParameter​(java.lang.String key,
                                 java.lang.String value)
                          throws java.lang.IllegalStateException
        Add a parameter with the given key and value.
        Parameters:
        key - The parameter name
        value - The parameter value
        Throws:
        java.lang.IllegalStateException - If the parameter count limit has been reached
      • setURLDecoder

        public void setURLDecoder​(UDecoder u)
        Set the URL decoder to use for decoding parameter names and values.
        Parameters:
        u - The URL decoder
      • processParameters

        public void processParameters​(byte[] bytes,
                                      int start,
                                      int len)
        Process the given byte array as a set of URL-encoded parameters using the current character set.
        Parameters:
        bytes - The byte array containing the parameters
        start - The start index in the byte array
        len - The length of the parameter data in the byte array
      • processParameters

        public void processParameters​(MessageBytes data,
                                      java.nio.charset.Charset charset)
        Process the given MessageBytes as a set of URL-encoded parameters using the specified character set.
        Parameters:
        data - The MessageBytes containing the parameters
        charset - The character set to use for decoding
      • toString

        public java.lang.String toString()
        Debug purpose
        Overrides:
        toString in class java.lang.Object