Package org.apache.http.message
Class HeaderGroup
java.lang.Object
org.apache.http.message.HeaderGroup
- All Implemented Interfaces:
Cloneable
public class HeaderGroup extends Object implements Cloneable
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
- Author:
- Michael Becke
-
Constructor Summary
Constructors Constructor Description HeaderGroup()Constructor for HeaderGroup. -
Method Summary
Modifier and Type Method Description voidaddHeader(Header header)Adds the given header to the group.voidclear()Removes any contained headers.Objectclone()Creates and returns a copy of thisObject.booleancontainsHeader(String name)Tests if headers with the given name are contained within this group.HeaderGroupcopy()Returns a copy of this objectHeader[]getAllHeaders()Gets all of the headers contained within this group.HeadergetCondensedHeader(String name)Gets a header representing all of the header values with the given name.HeadergetFirstHeader(String name)Gets the first header with the given name.Header[]getHeaders(String name)Gets all of the headers with the given name.HeadergetLastHeader(String name)Gets the last header with the given name.HeaderIteratoriterator()Returns an iterator over this group of headers.HeaderIteratoriterator(String name)Returns an iterator over the headers with a given name in this group.voidremoveHeader(Header header)Removes the given header.voidsetHeaders(Header[] headers)Sets all of the headers contained within this group overriding any existing headers.voidupdateHeader(Header header)Replaces the first occurence of the header with the same name.
-
Constructor Details
-
HeaderGroup
public HeaderGroup()Constructor for HeaderGroup.
-
-
Method Details
-
clear
public void clear()Removes any contained headers. -
addHeader
Adds the given header to the group. The order in which this header was added is preserved.- Parameters:
header- the header to add
-
removeHeader
Removes the given header.- Parameters:
header- the header to remove
-
updateHeader
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
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
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
nullif no headers by the given name are present
-
getHeaders
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
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
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
Gets all of the headers contained within this group.- Returns:
- an array of length >= 0
-
containsHeader
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:
trueif at least one header with the name is contained,falseotherwise
-
iterator
Returns an iterator over this group of headers.- Returns:
- iterator over this group of headers.
- Since:
- 4.0
-
iterator
Returns an iterator over the headers with a given name in this group.- Parameters:
name- the name of the headers over which to iterate, ornullfor all headers- Returns:
- iterator over some headers in this group.
- Since:
- 4.0
-
copy
Returns a copy of this object- Returns:
- copy of this object
-
clone
Description copied from class:ObjectCreates and returns a copy of thisObject. The default implementation returns a so-called "shallow" copy: It creates a new instance of the same class and then copies the field values (including object references) from this instance to the new instance. A "deep" copy, in contrast, would also recursively clone nested objects. A subclass that needs to implement this kind of cloning should callsuper.clone()to create the new instance and then create deep copies of the nested, mutable objects.- Overrides:
clonein classObject- Returns:
- a copy of this object.
- Throws:
CloneNotSupportedException- if this object's class does not implement theCloneableinterface.
-