Spring for Android

org.springframework.http
Class HttpHeaders

java.lang.Object
  extended by org.springframework.http.HttpHeaders
All Implemented Interfaces:
java.util.Map<java.lang.String,java.util.List<java.lang.String>>, MultiValueMap<java.lang.String,java.lang.String>

public class HttpHeaders
extends java.lang.Object
implements MultiValueMap<java.lang.String,java.lang.String>

Represents HTTP request and response headers, mapping string header names to list of string values.

In addition to the normal methods defined by Map, this class offers the following convenience methods:

Since:
1.0
Author:
Arjen Poutsma, Roy Clarkson

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
HttpHeaders()
          Constructs a new, empty instance of the HttpHeaders object.
 
Method Summary
 void add(java.lang.String headerName, java.lang.String headerValue)
          Add the given, single header value under the given name.
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> entrySet()
           
 boolean equals(java.lang.Object other)
           
 java.util.List<java.lang.String> get(java.lang.Object key)
           
 java.util.List<MediaType> getAccept()
          Return the list of acceptable media types, as specified by the Accept header.
 java.util.List<java.nio.charset.Charset> getAcceptCharset()
          Return the list of acceptable charsets, as specified by the Accept-Charset header.
 java.util.List<ContentCodingType> getAcceptEncoding()
          Return the list of acceptable coding types, as specified by the Accept-Encoding header.
 java.lang.String getAcceptLanguage()
          Return the accept language, as specified by the Accept-Language header.
 java.util.Set<HttpMethod> getAllow()
          Return the set of allowed HTTP methods, as specified by the Allow header.
 java.lang.String getAuthorization()
          Returns the value of the Authorization header.
 java.lang.String getCacheControl()
          Returns the value of the Cache-Control header.
 java.util.List<ContentCodingType> getContentEncoding()
          Return the list of content coding types, as specified by the Content-Encoding header.
 long getContentLength()
          Return the length of the body in bytes, as specified by the Content-Length header.
 MediaType getContentType()
          Return the media type of the body, as specified by the Content-Type header.
 long getDate()
          Returns the date and time at which the message was created, as specified by the Date header.
 java.lang.String getETag()
          Returns the entity tag of the body, as specified by the ETag header.
 long getExpires()
          Returns the date and time at which the message is no longer valid, as specified by the Expires header.
 java.lang.String getFirst(java.lang.String headerName)
          Return the first header value for the given header name, if any.
 java.util.List<java.lang.String> getIfNoneMatch()
          Returns the value of the If-None-Match header.
 long getIfNotModifiedSince()
          Returns the value of the IfModifiedSince header.
 long getLastModified()
          Returns the time the resource was last changed, as specified by the Last-Modified header.
 java.net.URI getLocation()
          Return the (new) location of a resource, as specified by the Location header.
 java.lang.String getPragma()
          Returns the value of the Pragma header.
 java.lang.String getUserAgent()
          Returns the value of the User-Agent header.
 int hashCode()
           
 boolean isEmpty()
           
 java.util.Set<java.lang.String> keySet()
           
 java.util.List<java.lang.String> put(java.lang.String key, java.util.List<java.lang.String> value)
           
 void putAll(java.util.Map<? extends java.lang.String,? extends java.util.List<java.lang.String>> m)
           
static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers)
          Returns HttpHeaders object that can only be read, not written to.
 java.util.List<java.lang.String> remove(java.lang.Object key)
           
 void set(java.lang.String headerName, java.lang.String headerValue)
          Set the given, single header value under the given name.
 void setAccept(java.util.List<MediaType> acceptableMediaTypes)
          Set the list of acceptable media types, as specified by the Accept header.
 void setAcceptCharset(java.util.List<java.nio.charset.Charset> acceptableCharsets)
          Set the list of acceptable charsets, as specified by the Accept-Charset header.
 void setAcceptEncoding(ContentCodingType acceptableEncodingType)
          Set the acceptable coding type, as specified by the Accept-Encoding header.
 void setAcceptEncoding(java.util.List<ContentCodingType> acceptableEncodingTypes)
          Set the list of acceptable coding types, as specified by the Accept-Encoding header.
 void setAcceptLanguage(java.lang.String acceptLanguage)
          Set the accept language, as specified by the Accept-Language header.
 void setAll(java.util.Map<java.lang.String,java.lang.String> values)
          Set the given values under.
 void setAllow(java.util.Set<HttpMethod> allowedMethods)
          Set the set of allowed HTTP methods, as specified by the Allow header.
 void setAuthorization(HttpAuthentication httpAuthentication)
          Sets a value for the Authorization header.
 void setCacheControl(java.lang.String cacheControl)
          Sets the (new) value of the Cache-Control header.
 void setContentDispositionFormData(java.lang.String name, java.lang.String filename)
          Sets the (new) value of the Content-Disposition header for form-data.
 void setContentEncoding(ContentCodingType contentEncodingType)
          Set the content coding type, as specified by the Content-Encoding header.
 void setContentEncoding(java.util.List<ContentCodingType> contentEncodingTypes)
          Set the list of content coding types, as specified by the Content-Encoding header.
 void setContentLength(long contentLength)
          Set the length of the body in bytes, as specified by the Content-Length header.
 void setContentType(MediaType mediaType)
          Set the media type of the body, as specified by the Content-Type header.
 void setDate(long date)
          Sets the date and time at which the message was created, as specified by the Date header.
 void setETag(java.lang.String eTag)
          Sets the (new) entity tag of the body, as specified by the ETag header.
 void setExpires(long expires)
          Sets the date and time at which the message is no longer valid, as specified by the Expires header.
 void setIfModifiedSince(long ifModifiedSince)
          Sets the (new) value of the If-Modified-Since header.
 void setIfNoneMatch(java.util.List<java.lang.String> ifNoneMatchList)
          Sets the (new) values of the If-None-Match header.
 void setIfNoneMatch(java.lang.String ifNoneMatch)
          Sets the (new) value of the If-None-Match header.
 void setLastModified(long lastModified)
          Sets the time the resource was last changed, as specified by the Last-Modified header.
 void setLocation(java.net.URI location)
          Set the (new) location of a resource, as specified by the Location header.
 void setPragma(java.lang.String pragma)
          Sets the (new) value of the Pragma header.
 void setUserAgent(java.lang.String userAgent)
          Sets the (new) value of the User-Agent header.
 int size()
           
 java.util.Map<java.lang.String,java.lang.String> toSingleValueMap()
          Returns the first values contained in this MultiValueMap.
 java.lang.String toString()
           
 java.util.Collection<java.util.List<java.lang.String>> values()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HttpHeaders

public HttpHeaders()
Constructs a new, empty instance of the HttpHeaders object.

Method Detail

readOnlyHttpHeaders

public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers)
Returns HttpHeaders object that can only be read, not written to.


setAccept

public void setAccept(java.util.List<MediaType> acceptableMediaTypes)
Set the list of acceptable media types, as specified by the Accept header.

Parameters:
acceptableMediaTypes - the acceptable media types

getAccept

public java.util.List<MediaType> getAccept()
Return the list of acceptable media types, as specified by the Accept header.

Returns an empty list when the acceptable media types are unspecified.

Returns:
the acceptable media types

setAcceptCharset

public void setAcceptCharset(java.util.List<java.nio.charset.Charset> acceptableCharsets)
Set the list of acceptable charsets, as specified by the Accept-Charset header.

Parameters:
acceptableCharsets - the acceptable charsets

getAcceptCharset

public java.util.List<java.nio.charset.Charset> getAcceptCharset()
Return the list of acceptable charsets, as specified by the Accept-Charset header.

Returns:
the acceptable charsets

setAcceptEncoding

public void setAcceptEncoding(java.util.List<ContentCodingType> acceptableEncodingTypes)
Set the list of acceptable coding types, as specified by the Accept-Encoding header.

Parameters:
acceptableEncodingTypes - the acceptable content coding types
See Also:
setAcceptEncoding(ContentCodingType)

setAcceptEncoding

public void setAcceptEncoding(ContentCodingType acceptableEncodingType)
Set the acceptable coding type, as specified by the Accept-Encoding header.

Parameters:
acceptableEncodingType - the acceptable content coding type
See Also:
setAcceptEncoding(List)

getAcceptEncoding

public java.util.List<ContentCodingType> getAcceptEncoding()
Return the list of acceptable coding types, as specified by the Accept-Encoding header.

Returns an empty list when the acceptable content coding types are unspecified.

Returns:
the acceptable content coding types

setAcceptLanguage

public void setAcceptLanguage(java.lang.String acceptLanguage)
Set the accept language, as specified by the Accept-Language header.

Parameters:
acceptLanguage - the accept language

getAcceptLanguage

public java.lang.String getAcceptLanguage()
Return the accept language, as specified by the Accept-Language header.

Returns:
the accept language

setAllow

public void setAllow(java.util.Set<HttpMethod> allowedMethods)
Set the set of allowed HTTP methods, as specified by the Allow header.

Parameters:
allowedMethods - the allowed methods

getAllow

public java.util.Set<HttpMethod> getAllow()
Return the set of allowed HTTP methods, as specified by the Allow header.

Returns an empty set when the allowed methods are unspecified.

Returns:
the allowed methods

setAuthorization

public void setAuthorization(HttpAuthentication httpAuthentication)
Sets a value for the Authorization header.

Parameters:
httpAuthentication - an http-based authentication representation

getAuthorization

public java.lang.String getAuthorization()
Returns the value of the Authorization header.

Returns:
the Authorization header value

setCacheControl

public void setCacheControl(java.lang.String cacheControl)
Sets the (new) value of the Cache-Control header.

Parameters:
cacheControl - the value of the header

getCacheControl

public java.lang.String getCacheControl()
Returns the value of the Cache-Control header.

Returns:
the value of the header

setContentDispositionFormData

public void setContentDispositionFormData(java.lang.String name,
                                          java.lang.String filename)
Sets the (new) value of the Content-Disposition header for form-data.

Parameters:
name - the control name
filename - the filename, may be null

setContentEncoding

public void setContentEncoding(java.util.List<ContentCodingType> contentEncodingTypes)
Set the list of content coding types, as specified by the Content-Encoding header.

Parameters:
contentEncodingTypes - the content coding types
See Also:
setContentEncoding(ContentCodingType)

setContentEncoding

public void setContentEncoding(ContentCodingType contentEncodingType)
Set the content coding type, as specified by the Content-Encoding header.

Parameters:
contentEncodingType - the content coding type
See Also:
setContentEncoding(List)

getContentEncoding

public java.util.List<ContentCodingType> getContentEncoding()
Return the list of content coding types, as specified by the Content-Encoding header.

Returns an empty list when the content coding type(s) are unspecified.

Returns:
the content coding types

setContentLength

public void setContentLength(long contentLength)
Set the length of the body in bytes, as specified by the Content-Length header.

Parameters:
contentLength - the content length

getContentLength

public long getContentLength()
Return the length of the body in bytes, as specified by the Content-Length header.

Returns -1 when the content-length is unknown.

Returns:
the content length

setContentType

public void setContentType(MediaType mediaType)
Set the media type of the body, as specified by the Content-Type header.

Parameters:
mediaType - the media type

getContentType

public MediaType getContentType()
Return the media type of the body, as specified by the Content-Type header.

Returns null when the content-type is unknown.

Returns:
the content type

setDate

public void setDate(long date)
Sets the date and time at which the message was created, as specified by the Date header.

The date should be specified as the number of milliseconds since January 1, 1970 GMT.

Parameters:
date - the date

getDate

public long getDate()
Returns the date and time at which the message was created, as specified by the Date header.

The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

Returns:
the creation date/time
Throws:
java.lang.IllegalArgumentException - if the value can't be converted to a date

setETag

public void setETag(java.lang.String eTag)
Sets the (new) entity tag of the body, as specified by the ETag header.

Parameters:
eTag - the new entity tag

getETag

public java.lang.String getETag()
Returns the entity tag of the body, as specified by the ETag header.

Returns:
the entity tag

setExpires

public void setExpires(long expires)
Sets the date and time at which the message is no longer valid, as specified by the Expires header.

The date should be specified as the number of milliseconds since January 1, 1970 GMT.

Parameters:
expires - the new expires header value

getExpires

public long getExpires()
Returns the date and time at which the message is no longer valid, as specified by the Expires header.

The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

Returns:
the expires value

setIfModifiedSince

public void setIfModifiedSince(long ifModifiedSince)
Sets the (new) value of the If-Modified-Since header.

The date should be specified as the number of milliseconds since January 1, 1970 GMT.

Parameters:
ifModifiedSince - the new value of the header

getIfNotModifiedSince

public long getIfNotModifiedSince()
Returns the value of the IfModifiedSince header.

The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

Returns:
the header value

setIfNoneMatch

public void setIfNoneMatch(java.lang.String ifNoneMatch)
Sets the (new) value of the If-None-Match header.

Parameters:
ifNoneMatch - the new value of the header

setIfNoneMatch

public void setIfNoneMatch(java.util.List<java.lang.String> ifNoneMatchList)
Sets the (new) values of the If-None-Match header.

Parameters:
ifNoneMatchList - the new value of the header

getIfNoneMatch

public java.util.List<java.lang.String> getIfNoneMatch()
Returns the value of the If-None-Match header.

Returns:
the header value

setLastModified

public void setLastModified(long lastModified)
Sets the time the resource was last changed, as specified by the Last-Modified header.

The date should be specified as the number of milliseconds since January 1, 1970 GMT.

Parameters:
lastModified - the last modified date

getLastModified

public long getLastModified()
Returns the time the resource was last changed, as specified by the Last-Modified header.

The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

Returns:
the last modified date

setLocation

public void setLocation(java.net.URI location)
Set the (new) location of a resource, as specified by the Location header.

Parameters:
location - the location

getLocation

public java.net.URI getLocation()
Return the (new) location of a resource, as specified by the Location header.

Returns null when the location is unknown.

Returns:
the location

setPragma

public void setPragma(java.lang.String pragma)
Sets the (new) value of the Pragma header.

Parameters:
pragma - the value of the header

getPragma

public java.lang.String getPragma()
Returns the value of the Pragma header.

Returns:
the value of the header

setUserAgent

public void setUserAgent(java.lang.String userAgent)
Sets the (new) value of the User-Agent header.

Parameters:
userAgent - the value of the header

getUserAgent

public java.lang.String getUserAgent()
Returns the value of the User-Agent header.

Returns:
the value of the header

getFirst

public java.lang.String getFirst(java.lang.String headerName)
Return the first header value for the given header name, if any.

Specified by:
getFirst in interface MultiValueMap<java.lang.String,java.lang.String>
Parameters:
headerName - the header name
Returns:
the first header value; or null

add

public void add(java.lang.String headerName,
                java.lang.String headerValue)
Add the given, single header value under the given name.

Specified by:
add in interface MultiValueMap<java.lang.String,java.lang.String>
Parameters:
headerName - the header name
headerValue - the header value
Throws:
java.lang.UnsupportedOperationException - if adding headers is not supported
See Also:
put(String, List), set(String, String)

set

public void set(java.lang.String headerName,
                java.lang.String headerValue)
Set the given, single header value under the given name.

Specified by:
set in interface MultiValueMap<java.lang.String,java.lang.String>
Parameters:
headerName - the header name
headerValue - the header value
Throws:
java.lang.UnsupportedOperationException - if adding headers is not supported
See Also:
put(String, List), add(String, String)

setAll

public void setAll(java.util.Map<java.lang.String,java.lang.String> values)
Description copied from interface: MultiValueMap
Set the given values under.

Specified by:
setAll in interface MultiValueMap<java.lang.String,java.lang.String>
Parameters:
values - the values.

toSingleValueMap

public java.util.Map<java.lang.String,java.lang.String> toSingleValueMap()
Description copied from interface: MultiValueMap
Returns the first values contained in this MultiValueMap.

Specified by:
toSingleValueMap in interface MultiValueMap<java.lang.String,java.lang.String>
Returns:
a single value representation of this map

size

public int size()
Specified by:
size in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>

get

public java.util.List<java.lang.String> get(java.lang.Object key)
Specified by:
get in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>

put

public java.util.List<java.lang.String> put(java.lang.String key,
                                            java.util.List<java.lang.String> value)
Specified by:
put in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>

remove

public java.util.List<java.lang.String> remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>

putAll

public void putAll(java.util.Map<? extends java.lang.String,? extends java.util.List<java.lang.String>> m)
Specified by:
putAll in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>

clear

public void clear()
Specified by:
clear in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>

keySet

public java.util.Set<java.lang.String> keySet()
Specified by:
keySet in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>

values

public java.util.Collection<java.util.List<java.lang.String>> values()
Specified by:
values in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>

entrySet

public java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> entrySet()
Specified by:
entrySet in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>

equals

public boolean equals(java.lang.Object other)
Specified by:
equals in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
Overrides:
hashCode in class java.lang.Object

toString

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

Spring for Android