org.apache.commons.httpclient

Class HeaderGroup


public class HeaderGroup
extends Object

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:
2.0beta1

Constructor Summary

HeaderGroup()
Constructor for HeaderGroup.

Method Summary

void
addHeader(Header header)
Adds the given header to the group.
void
clear()
Removes any contained headers.
boolean
containsHeader(String name)
Tests if headers with the given name are contained within this group.
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.
Iterator<E>
getIterator()
Returns an iterator over this group of headers.
Header
getLastHeader(String name)
Gets the last header with the given name.
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.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

HeaderGroup

public HeaderGroup()
Constructor for HeaderGroup.
Usages and Demos :

View More Examples of HeaderGroup()
   1:     private RequestLine requestLine = null;
   2:     private HeaderGroup headers = new HeaderGroup();
   3:     private InputStream entity = null;
   4: 
   5:     public SimpleRequest() {

View Full Code Here
   1:     private String phrase = HttpStatus.getStatusText(HttpStatus.SC_OK);
   2:     private HeaderGroup headers = new HeaderGroup();
   3:     private InputStream entity = null;
   4: 
   5:     public SimpleResponse() {

View Full Code Here

Method Details

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

clear

public void clear()
Removes any contained headers.

containsHeader

public boolean containsHeader(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

getAllHeaders

public Header[] getAllHeaders()
Gets all of the headers contained within this group.
Returns:
an array of length >= 0

getCondensedHeader

public Header getCondensedHeader(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

getFirstHeader

public Header getFirstHeader(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

getHeaders

public Header[] getHeaders(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

getIterator

public Iterator<E> getIterator()
Returns an iterator over this group of headers.
Returns:
iterator over this group of headers.
Since:
3.0

getLastHeader

public Header getLastHeader(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

removeHeader

public void removeHeader(Header header)
Removes the given header.
Parameters:
header - the header to remove

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