public class HTTPMultiMap extends Object
field1=valueA&field1=valueBbut RequestProperties come out as comma separated "arrays" after a single key, e.g.
Accept: text/html,application/xhtml+xmlInternally (within this.map), the values are NOT encoded. Encoding is performed at the "last minute" (in toQueryString)
Modifier and Type | Field and Description |
---|---|
protected Map<String,List<String>> |
map |
protected String |
querySeparator
alternative is ';', @see http://www.w3.org/TR/1999/REC-html401-19991224/appendix/notes.html#h-B.2.2
|
Constructor and Description |
---|
HTTPMultiMap()
Default (most common) constructor - results are not sorted...
|
HTTPMultiMap(boolean sorted,
Map<String,List<String>> copyFrom)
Detailed constructor
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(Object field,
Object value)
Add the field=value pair if not already present
synchronized so as to be slightly thread-safe
|
void |
addFieldValuePairs(Object... pairs)
Add pairs of field=value
|
void |
addMultiMap(HTTPMultiMap mm)
Add another MultiMap
|
void |
addQueryString(URLEncoding wasEncoded,
String queryString)
More for convenience, adds an existing query string to our map
|
void |
addSingleMap(Map<?,?> singleMap)
Add the entire contents of a map of field=value pairs
|
void |
applyHeadersToConnection(URLConnection conn)
Adds all the field=value pairs to the URLConnection
If a field has multiple values, makes multiple calls to conn.addRequestProperty()
|
String |
getHeaderString(String field,
URLEncoding encoding)
Get the String representing value(s) for a single field
Formatted as for a Header, with multiple values comma separated, e.g field=val1,val2
|
Map<String,List<String>> |
getMap()
direct access to the underlying map for advanced operations
should not be needed, use with caution
|
protected List<String> |
newList() |
List<String> |
remove(String field)
remove an entire field from the map
|
boolean |
remove(String field,
String value)
remove a single field/value from the map.
|
void |
setFieldValuePairs(Object... pairs)
Sets the field=value pairs, removing all previous values
|
static String |
stripLeadingAmpOrQuestion(String in)
Removes a leading ampersand or question mark from a String
|
String |
toQueryString(URLEncoding encoding)
Creates a String representing queries for all the fields.
|
Map<String,String> |
toSingleMap(boolean sorted,
boolean concatMultiple)
Tries to convert this to a "single map" (Map
|
String |
toString() |
String |
useSemicolonQuerySeparator(boolean useSemiColon)
Switches to semicolon instead of ampersand
|
protected String querySeparator
public HTTPMultiMap(boolean sorted, Map<String,List<String>> copyFrom)
sorted
- copyFrom
- if not null, copy values from this map (e.g. as a copy-constructor)public HTTPMultiMap()
public Map<String,String> toSingleMap(boolean sorted, boolean concatMultiple)
sorted
- whether result should be sorted by fieldconcatMultiple
- if true, multiple values get concatenated (using List.toString() sans square brackets)IllegalStateException
- if we have multiple values for a key and !concatMultiplepublic boolean add(Object field, Object value)
field
- non-nullvalue
- may be null, in which case EXISTS ("") will be usedpublic void setFieldValuePairs(Object... pairs)
pairs
- may be null, if not must have an even lengthpublic void addSingleMap(Map<?,?> singleMap)
singleMap
- May be null. Should be Mappublic void addMultiMap(HTTPMultiMap mm)
mm
- May be nullpublic void addFieldValuePairs(Object... pairs)
pairs
- may be null, if not must have an even lengthpublic void addQueryString(URLEncoding wasEncoded, String queryString)
wasEncoded
- existing encoding, null will become NONEqueryString
- non-nullpublic String useSemicolonQuerySeparator(boolean useSemiColon)
useSemiColon
- public String toQueryString(URLEncoding encoding)
encoding
- public String getHeaderString(String field, URLEncoding encoding)
field
- if not present, "" will be returnedencoding
- public void applyHeadersToConnection(URLConnection conn)
conn
- public List<String> remove(String field)
field
- public boolean remove(String field, String value)
field
- value
- public Map<String,List<String>> getMap()
public static String stripLeadingAmpOrQuestion(String in)
in
- non-null