Top Description Fields Constructors Methods
org.apache.http.message

public Class HeaderGroup

extends Object
implements Cloneable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Cloneable
Imports
java.io.Serializable, java.util.ArrayList, .Collections, .List, .Locale, org.apache.http.Header, .HeaderIterator, org.apache.http.util.CharArrayBuffer

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

Field Summary

Modifier and TypeField and Description
private static final Header[]
private final List<Header>
headers

The list of headers for this group, in the order in which they were added

private static final long

Constructor Summary

AccessConstructor and Description
public
HeaderGroup()

Constructor for HeaderGroup.

Method Summary

Modifier and TypeMethod and Description
public void
addHeader(final Header
the header to add
header
)

Adds the given header to the group.

public void
clear()

Removes any contained headers.

public Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public boolean

Returns:

true if at least one header with the name is contained, false otherwise
containsHeader
(final String
the header name to test for
name
)

Tests if headers with the given name are contained within this group.

public HeaderGroup

Returns:

copy of this object
copy
()

Returns a copy of this object

public Header[]

Returns:

an array of length ≥ 0
getAllHeaders
()

Gets all of the headers contained within this group.

public Header

Returns:

a header with a condensed value or null if no headers by the given name are present
getCondensedHeader
(final String
the name of the header(s) to get
name
)

Gets a header representing all of the header values with the given name.

public Header

Returns:

the first header or null
getFirstHeader
(final String
the name of the header to get
name
)

Gets the first header with the given name.

public Header[]

Returns:

an array of length ≥ 0
getHeaders
(final String
the name of the header(s) to get
name
)

Gets all of the headers with the given name.

public Header

Returns:

the last header or null
getLastHeader
(final String
the name of the header to get
name
)

Gets the last header with the given name.

public HeaderIterator

Returns:

iterator over this group of headers.
iterator
()

Returns an iterator over this group of headers.

public HeaderIterator

Returns:

iterator over some headers in this group.
iterator
(final String
the name of the headers over which to iterate, or null for all headers
name
)

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

public void
removeHeader(final Header
the header to remove
header
)

Removes the given header.

public void
setHeaders(final Header[]
the headers to set
headers
)

Sets all of the headers contained within this group overriding any existing headers.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public void
updateHeader(final Header
the new header that should replace the first header with the same name if present in the list.
header
)

Replaces the first occurence of the header with the same name.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

EMPTYback to summary
private static final Header[] EMPTY
headersback to summary
private final List<Header> headers

The list of headers for this group, in the order in which they were added

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

HeaderGroupback to summary
public HeaderGroup()

Constructor for HeaderGroup.

Method Detail

addHeaderback to summary
public void addHeader(final Header header)

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

Parameters
header:Header

the header to add

clearback to summary
public void clear()

Removes any contained headers.

cloneback to summary
public Object clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Object

a clone of this instance.

Annotations
@Override
Exceptions
CloneNotSupportedException:
if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.
containsHeaderback to summary
public boolean containsHeader(final String name)

Tests if headers with the given name are contained within this group.

Header name comparison is case insensitive.

Parameters
name:String

the header name to test for

Returns:boolean

true if at least one header with the name is contained, false otherwise

copyback to summary
public HeaderGroup copy()

Returns a copy of this object

Returns:HeaderGroup

copy of this object

Since
4.0
getAllHeadersback to summary
public Header[] getAllHeaders()

Gets all of the headers contained within this group.

Returns:Header[]

an array of length ≥ 0

getCondensedHeaderback to summary
public Header getCondensedHeader(final 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:String

the name of the header(s) to get

Returns:Header

a header with a condensed value or null if no headers by the given name are present

getFirstHeaderback to summary
public Header getFirstHeader(final String name)

Gets the first header with the given name.

Header name comparison is case insensitive.

Parameters
name:String

the name of the header to get

Returns:Header

the first header or null

getHeadersback to summary
public Header[] getHeaders(final 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:String

the name of the header(s) to get

Returns:Header[]

an array of length ≥ 0

getLastHeaderback to summary
public Header getLastHeader(final String name)

Gets the last header with the given name.

Header name comparison is case insensitive.

Parameters
name:String

the name of the header to get

Returns:Header

the last header or null

iteratorback to summary
public HeaderIterator iterator()

Returns an iterator over this group of headers.

Returns:HeaderIterator

iterator over this group of headers.

Since
4.0
iteratorback to summary
public HeaderIterator iterator(final String name)

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

Parameters
name:String

the name of the headers over which to iterate, or null for all headers

Returns:HeaderIterator

iterator over some headers in this group.

Since
4.0
removeHeaderback to summary
public void removeHeader(final Header header)

Removes the given header.

Parameters
header:Header

the header to remove

setHeadersback to summary
public void setHeaders(final 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:Header[]

the headers to set

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
updateHeaderback to summary
public void updateHeader(final 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:Header

the new header that should replace the first header with the same name if present in the list.