java.util.Map <java.lang.String ,
java.util.List <java.lang.String >>.
The keys are case-insensitive Strings representing the header names and
the value associated with each key is
a List<String> with one
element for each occurrence of the header name in the request or response.
For example, if a response header instance contains one key "HeaderName" with two values "value1 and value2" then this object is output as two header lines:
All the normalHeaderName: value1 HeaderName: value2
java.util.Map methods are provided, but the
following additional convenience methods are most likely to be used:
getFirst(String) returns a single valued header or the first
value of a multi-valued header.
add(String, String) adds the given header value to the list
for the given key.
set(String, String) sets the given header field to the single
value given overwriting any existing values in the value list.
An instance of Headers is either mutable or immutable.
A mutable headers allows to add, remove, or modify header names and
values, e.g. the instance returned by HttpExchange#getResponseHeaders().
An immutable headers disallows any modification to header names or
values, e.g. the instance returned by HttpExchange#getRequestHeaders().
The mutator methods for an immutable headers instance unconditionally throw
UnsupportedOperationException.
All methods in this class reject null values for keys and values.
null keys will never be present in HTTP request or response headers.
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | clear()
Implements java. Removes all of the mappings from this map (optional operation). |
| public boolean | containsKey(Object key)
Implements java. Returns |
| public boolean | containsValue(Object value)
Implements java. Returns |
| public Set | entrySet()
Implements java. Returns a |
| public boolean | equals(Object o)
Overrides java. Implements java. Compares the specified object with this map for equality. |
| public List | get(Object key)
Implements java. Returns the value to which the specified key is mapped,
or |
| public String | |
| public int | hashCode()
Overrides java. Implements java. Returns the hash code value for this map. |
| public boolean | |
| public Set | |
| private static String | |
| public static Headers | |
| public static Headers | |
| public List | put(String key, List<String> value)
Implements java. Associates the specified value with the specified key in this map (optional operation). |
| public void | |
| public List | remove(Object key)
Implements java. Removes the mapping for a key from this map if it is present (optional operation). |
| public void | replaceAll(BiFunction<? super String, ? super List<String>, ? extends List<String>> function)
Overrides default java. Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception (optional operation). |
| public void | |
| public int | |
| public String | |
| public Collection | values()
Implements java. Returns a |
| map | back to summary |
|---|---|
| pack-priv HashMap<String, List<String>> map | |
| Headers | back to summary |
|---|---|
| public Headers() Creates an empty instance of | |
| Headers | back to summary |
|---|---|
| public Headers(Map<String, List<String>> headers) Creates a mutable
| |
| add | back to summary |
|---|---|
| public void add(String key, String value) Adds the given | |
| clear | back to summary |
|---|---|
| public void clear() Implements java. Doc from java. Removes all of the mappings from this map (optional operation). The map will be empty after this call returns.
| |
| containsKey | back to summary |
|---|---|
| public boolean containsKey(Object key) Implements java. Doc from java. Returns
| |
| containsValue | back to summary |
|---|---|
| public boolean containsValue(Object value) Implements java. Doc from java. Returns
| |
| entrySet | back to summary |
|---|---|
| public Set Implements java. Doc from java. Returns a
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Overrides java. Implements java. Doc from java. Compares the specified object with this map for equality. Returns
| |
| get | back to summary |
|---|---|
| public List Implements java. Doc from java. Returns the value to which the specified key is mapped,
or More formally, if this map contains a mapping from a key
If this map permits null values, then a return value of
| |
| getFirst | back to summary |
|---|---|
| public String getFirst(String key) Returns the first value from the | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements java. Doc from java. Returns the hash code value for this map. The hash code of a map is
defined to be the sum of the hash codes of each entry in the map's
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements java. Doc from java. Returns
| |
| keySet | back to summary |
|---|---|
| public Set Implements java. Doc from java. Returns a
| |
| normalize | back to summary |
|---|---|
| private static String normalize(String key) Returns the normalized header name of the following form: the first character in upper-case, the rest in lower-case. The input header name is assumed to be encoded in ASCII. Implementation Specification This method is performance-sensitive; update with care.
| |
| of | back to summary |
|---|---|
| public static Headers of(String... headers) Returns an immutable The supplied
| |
| of | back to summary |
|---|---|
| public static Headers of(Map<String, List<String>> headers) Returns an immutable | |
| put | back to summary |
|---|---|
| public List Implements java. Doc from java. Associates the specified value with the specified key in this map
(optional operation). If the map previously contained a mapping for
the key, the old value is replaced by the specified value. (A map
| |
| putAll | back to summary |
|---|---|
| public void putAll(Map<? extends String, ? extends List<String>> t) Implements java. Doc from java. Copies all of the mappings from the specified map to this map
(optional operation). The effect of this call is equivalent to that
of calling
| |
| remove | back to summary |
|---|---|
| public List Implements java. Doc from java. Removes the mapping for a key from this map if it is present
(optional operation). More formally, if this map contains a mapping
from key Returns the value to which this map previously associated the key,
or If this map permits null values, then a return value of
The map will not contain a mapping for the specified key once the call returns.
| |
| replaceAll | back to summary |
|---|---|
| public void replaceAll(BiFunction<? super String, ? super List<String>, ? extends List<String>> function) Overrides default java. Doc from java. Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception (optional operation). Exceptions thrown by the function are relayed to the caller.
| |
| set | back to summary |
|---|---|
| public void set(String key, String value) Sets the given | |
| size | back to summary |
|---|---|
| public int size() Implements java. Doc from java. Returns the number of key-value mappings in this map. If the
map contains more than
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |
| values | back to summary |
|---|---|
| public Collection Implements java. Doc from java. Returns a
| |