Class PostData
java.lang.Object
nl.colorize.util.http.PostData
Represents data that has been sent as part of an HTTP request and is
encoded using the
application/x-www-form-urlencoded content type.
This is commonly used in URL query strings, and in "classic" HTML forms
as documented in sections 4.10.21.7 and 4.10.21.8 of the
HTML specification.
Post data parameters consist of name/value pairs. This class provides two
ways to retrieve parameter values: getRequiredParameter(String)
(which will throw an exception if the parameter is not present), and
getOptionalParameter(String, String) (which will return a default
value for missing parameters). Note that the parameter is considered
"missing" if it is either not present at all, or if the parameter name is
specified but its value is empty.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true if thisPostDatacontains at least one parameter with the specified name.static PostDataCreates aPostDatainstance from a number of key/value pairs.static PostDataCreates aPostDatainstance from existing key/value pairs.static PostDataCreates aPostDatainstance from a list of tuples, with each tuple acting as a name/value pauir.static PostDataempty()Utility method that returns aPostDatainstance that indicates no parameters have been specified.encode()Encodes thisPostDatainto a string that follows theapplication/x-www-form-urlencodednotation, using the UTF-8 character encoding.Encodes thisPostDatainto a string that follows theapplication/x-www-form-urlencodednotation.booleangetOptionalParameter(String name, String defaultValue) Returns either the value of the parameter with the specified name, ordefaultValueif no parameter with that name exists.getParameterValues(String name) Returns all values for the parameter with the specified name.getRequiredParameter(String name) Returns the value of the parameter with the specified name.inthashCode()booleanisEmpty()iterator()Creates a newPostDatainstance by merging all parameters from this instance with another one.static PostDataParsesPostDatafrom the specified string using the UTF-8 character encoding.static PostDataParsesPostDatafrom the specified string.stream()toString()Methods inherited from interface Iterable
forEach, spliterator
-
Method Details
-
getRequiredParameter
Returns the value of the parameter with the specified name. If multiple parameters match the requested name, the first occurrence will be returned. UsegetParameterValues(String)if you want to retrieve all matching parameters.- Throws:
IllegalStateException- if no parameter with that name exists.
-
getOptionalParameter
-
getParameterValues
-
contains
-
isEmpty
public boolean isEmpty() -
iterator
-
stream
-
merge
Creates a newPostDatainstance by merging all parameters from this instance with another one.- Throws:
IllegalArgumentException- if both instances contain a parameter with the same name.
-
encode
-
encode
-
equals
-
hashCode
-
toString
-
create
Creates aPostDatainstance from a number of key/value pairs. When specifying multiple key/value pairs, therestparameter expects the orderkey1, value1, key2, value2, ....- Throws:
IllegalArgumentException- if the number of parameters is not a multiple of two.
-
create
-
create
-
parse
-
parse
-
empty
-