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

public Class HeaderGroup

extends Object
implements MessageHeaders, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.hc.core5.http.MessageHeaders
Known Direct Subclasses
org.apache.hc.core5.http.message.BasicHttpRequest, org.apache.hc.core5.http.message.BasicHttpResponse
Imports
java.io.Serializable, java.util.ArrayList, .Collections, .Iterator, .List, .Objects, org.apache.hc.core5.http.Header, .MessageHeaders, .ProtocolException, org.apache.hc.core5.util.CharArrayBuffer, .TextUtils

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 all headers.

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
)

Implements org.apache.hc.core5.http.MessageHeaders.containsHeader.

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

Returns:

number of occurrences of the header in the message.
countHeaders
(final String
the header name to check for.
name
)

Implements org.apache.hc.core5.http.MessageHeaders.countHeaders.

Checks if a certain header is present in this message and how many times.
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
)

Implements org.apache.hc.core5.http.MessageHeaders.getFirstHeader.

Gets the first header with the given name.
public Header

Returns:

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

Implements org.apache.hc.core5.http.MessageHeaders.getHeader.

Gets single 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
)

Implements org.apache.hc.core5.http.MessageHeaders.getHeaders.

Gets all of the headers with the given name.
public Header[]

Returns:

an array of length ≥ 0
getHeaders
()

Implements org.apache.hc.core5.http.MessageHeaders.getHeaders.

Gets all of the headers contained within this group.
public Header

Returns:

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

Implements org.apache.hc.core5.http.MessageHeaders.getLastHeader.

Gets the last header with the given name.
private boolean
headerEquals(final Header header1, final Header header2)

public Iterator<Header>

Returns:

iterator over this group of headers.
headerIterator
()

Implements org.apache.hc.core5.http.MessageHeaders.headerIterator.

Returns an iterator over this group of headers.
public Iterator<Header>

Returns:

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

Implements org.apache.hc.core5.http.MessageHeaders.headerIterator.

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

Returns:

true if a header was removed as a result of this call.
removeHeader
(final Header
the header to remove
header
)

Removes the first given header.

public boolean

Returns:

true if any header was removed as a result of this call.
removeHeaders
(final Header
the header to remove
header
)

Removes all headers that match the given header.

public boolean

Returns:

true if any header was removed as a result of this call.
removeHeaders
(final String
the name of the headers to be removed.
name
)

Removes all headers with a given name in this group.

public void
setHeader(final Header
the new header that should replace the first header with the same name if present in the list.
header
)

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

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.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

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 all headers.

containsHeaderback to summary
public boolean containsHeader(final String name)

Implements org.apache.hc.core5.http.MessageHeaders.containsHeader.

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

Annotations
@Override
countHeadersback to summary
public int countHeaders(final String name)

Implements org.apache.hc.core5.http.MessageHeaders.countHeaders.

Checks if a certain header is present in this message and how many times.

Header name comparison is case insensitive.

Parameters
name:String

the header name to check for.

Returns:int

number of occurrences of the header in the message.

Annotations
@Override
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 ",".

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)

Implements org.apache.hc.core5.http.MessageHeaders.getFirstHeader.

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

Annotations
@Override
getHeaderback to summary
public Header getHeader(final String name) throws ProtocolException

Implements org.apache.hc.core5.http.MessageHeaders.getHeader.

Gets single 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

Annotations
@Override
Exceptions
ProtocolException:
in case multiple headers with the given name are found.
getHeadersback to summary
public Header[] getHeaders(final String name)

Implements org.apache.hc.core5.http.MessageHeaders.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:String

the name of the header(s) to get

Returns:Header[]

an array of length ≥ 0

Annotations
@Override
getHeadersback to summary
public Header[] getHeaders()

Implements org.apache.hc.core5.http.MessageHeaders.getHeaders.

Gets all of the headers contained within this group.

Returns:Header[]

an array of length ≥ 0

Annotations
@Override
getLastHeaderback to summary
public Header getLastHeader(final String name)

Implements org.apache.hc.core5.http.MessageHeaders.getLastHeader.

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

Annotations
@Override
headerEqualsback to summary
private boolean headerEquals(final Header header1, final Header header2)
headerIteratorback to summary
public Iterator<Header> headerIterator()

Implements org.apache.hc.core5.http.MessageHeaders.headerIterator.

Returns an iterator over this group of headers.

Returns:Iterator<Header>

iterator over this group of headers.

Annotations
@Override
Since
5.0
headerIteratorback to summary
public Iterator<Header> headerIterator(final String name)

Implements org.apache.hc.core5.http.MessageHeaders.headerIterator.

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:Iterator<Header>

iterator over some headers in this group.

Annotations
@Override
Since
5.0
removeHeaderback to summary
public boolean removeHeader(final Header header)

Removes the first given header.

Parameters
header:Header

the header to remove

Returns:boolean

true if a header was removed as a result of this call.

removeHeadersback to summary
public boolean removeHeaders(final Header header)

Removes all headers that match the given header.

Parameters
header:Header

the header to remove

Returns:boolean

true if any header was removed as a result of this call.

Since
5.0
removeHeadersback to summary
public boolean removeHeaders(final String name)

Removes all headers with a given name in this group.

Parameters
name:String

the name of the headers to be removed.

Returns:boolean

true if any header was removed as a result of this call.

Since
5.0
setHeaderback to summary
public void setHeader(final Header header)

Replaces the first occurrence 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.

Since
5.0
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