Package org.apache.http.message
Class HeaderGroup
- java.lang.Object
-
- org.apache.http.message.HeaderGroup
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public class HeaderGroup extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable
A class for combining a set of headers. This class allows for multiple headers with the same name and keeps track of the order in which headers were added.- Since:
- 4.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description HeaderGroup()
Constructor for HeaderGroup.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addHeader(Header header)
Adds the given header to the group.void
clear()
Removes any contained headers.java.lang.Object
clone()
boolean
containsHeader(java.lang.String name)
Tests if headers with the given name are contained within this group.HeaderGroup
copy()
Returns a copy of this objectHeader[]
getAllHeaders()
Gets all of the headers contained within this group.Header
getCondensedHeader(java.lang.String name)
Gets a header representing all of the header values with the given name.Header
getFirstHeader(java.lang.String name)
Gets the first header with the given name.Header[]
getHeaders(java.lang.String name)
Gets all of the headers with the given name.Header
getLastHeader(java.lang.String name)
Gets the last header with the given name.HeaderIterator
iterator()
Returns an iterator over this group of headers.HeaderIterator
iterator(java.lang.String name)
Returns an iterator over the headers with a given name in this group.void
removeHeader(Header header)
Removes the given header.void
setHeaders(Header[] headers)
Sets all of the headers contained within this group overriding any existing headers.java.lang.String
toString()
void
updateHeader(Header header)
Replaces the first occurence of the header with the same name.
-
-
-
Method Detail
-
clear
public void clear()
Removes any contained headers.
-
addHeader
public void addHeader(Header header)
Adds the given header to the group. The order in which this header was added is preserved.- Parameters:
header
- the header to add
-
removeHeader
public void removeHeader(Header header)
Removes the given header.- Parameters:
header
- the header to remove
-
updateHeader
public void updateHeader(Header header)
Replaces the first occurence of the header with the same name. If no header with the same name is found the given header is added to the end of the list.- Parameters:
header
- the new header that should replace the first header with the same name if present in the list.
-
setHeaders
public void setHeaders(Header[] headers)
Sets all of the headers contained within this group overriding any existing headers. The headers are added in the order in which they appear in the array.- Parameters:
headers
- the headers to set
-
getCondensedHeader
public Header getCondensedHeader(java.lang.String name)
Gets a header representing all of the header values with the given name. If more that one header with the given name exists the values will be combined with a "," as per RFC 2616.Header name comparison is case insensitive.
- Parameters:
name
- the name of the header(s) to get- Returns:
- a header with a condensed value or
null
if no headers by the given name are present
-
getHeaders
public Header[] getHeaders(java.lang.String name)
Gets all of the headers with the given name. The returned array maintains the relative order in which the headers were added.Header name comparison is case insensitive.
- Parameters:
name
- the name of the header(s) to get- Returns:
- an array of length ≥ 0
-
getFirstHeader
public Header getFirstHeader(java.lang.String name)
Gets the first header with the given name.Header name comparison is case insensitive.
- Parameters:
name
- the name of the header to get- Returns:
- the first header or
null
-
getLastHeader
public Header getLastHeader(java.lang.String name)
Gets the last header with the given name.Header name comparison is case insensitive.
- Parameters:
name
- the name of the header to get- Returns:
- the last header or
null
-
getAllHeaders
public Header[] getAllHeaders()
Gets all of the headers contained within this group.- Returns:
- an array of length ≥ 0
-
containsHeader
public boolean containsHeader(java.lang.String name)
Tests if headers with the given name are contained within this group.Header name comparison is case insensitive.
- Parameters:
name
- the header name to test for- Returns:
true
if at least one header with the name is contained,false
otherwise
-
iterator
public HeaderIterator iterator()
Returns an iterator over this group of headers.- Returns:
- iterator over this group of headers.
- Since:
- 4.0
-
iterator
public HeaderIterator iterator(java.lang.String name)
Returns an iterator over the headers with a given name in this group.- Parameters:
name
- the name of the headers over which to iterate, ornull
for all headers- Returns:
- iterator over some headers in this group.
- Since:
- 4.0
-
copy
public HeaderGroup copy()
Returns a copy of this object- Returns:
- copy of this object
- Since:
- 4.0
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
- Throws:
java.lang.CloneNotSupportedException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-