public class

HeaderGroup

extends Object
implements Cloneable
java.lang.Object
   ↳ org.apache.http.message.HeaderGroup

Class Overview

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.

Summary

Public Constructors
HeaderGroup()
Constructor for HeaderGroup.
Public Methods
void addHeader(Header header)
Adds the given header to the group.
void clear()
Removes any contained headers.
Object clone()
Creates and returns a copy of this Object.
boolean containsHeader(String name)
Tests if headers with the given name are contained within this group.
HeaderGroup copy()
Returns a copy of this object
Header[] getAllHeaders()
Gets all of the headers contained within this group.
Header getCondensedHeader(String name)
Gets a header representing all of the header values with the given name.
Header getFirstHeader(String name)
Gets the first header with the given name.
Header[] getHeaders(String name)
Gets all of the headers with the given name.
Header getLastHeader(String name)
Gets the last header with the given name.
HeaderIterator iterator()
Returns an iterator over this group of headers.
HeaderIterator iterator(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.
void updateHeader(Header header)
Replaces the first occurence of the header with the same name.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public HeaderGroup ()

Since: API Level 1

Constructor for HeaderGroup.

Public Methods

public void addHeader (Header header)

Since: API Level 1

Adds the given header to the group. The order in which this header was added is preserved.

Parameters
header the header to add

public void clear ()

Since: API Level 1

Removes any contained headers.

public Object clone ()

Since: API Level 1

Creates and returns a copy of this Object. 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 call super.clone() to create the new instance and then create deep copies of the nested, mutable objects.

Returns
  • a copy of this object.

public boolean containsHeader (String name)

Since: API Level 1

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

public HeaderGroup copy ()

Since: API Level 1

Returns a copy of this object

Returns
  • copy of this object

public Header[] getAllHeaders ()

Since: API Level 1

Gets all of the headers contained within this group.

Returns
  • an array of length >= 0

public Header getCondensedHeader (String name)

Since: API Level 1

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

public Header getFirstHeader (String name)

Since: API Level 1

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

public Header[] getHeaders (String name)

Since: API Level 1

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

public Header getLastHeader (String name)

Since: API Level 1

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

public HeaderIterator iterator ()

Since: API Level 1

Returns an iterator over this group of headers.

Returns
  • iterator over this group of headers.

public HeaderIterator iterator (String name)

Since: API Level 1

Returns an iterator over the headers with a given name in this group.

Parameters
name the name of the headers over which to iterate, or null for all headers
Returns
  • iterator over some headers in this group.

public void removeHeader (Header header)

Since: API Level 1

Removes the given header.

Parameters
header the header to remove

public void setHeaders (Header[] headers)

Since: API Level 1

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

public void updateHeader (Header header)

Since: API Level 1

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.