BasicHeaderElementpublic class BasicHeaderElement extends Object implements HeaderElement, CloneableOne element of an HTTP header's value.
Some HTTP headers (such as the set-cookie header) have values that
can be decomposed into multiple elements. Such headers must be in the
following form:
header = [ element ] *( "," [ element ] )
element = name [ "=" [ value ] ] *( ";" [ param ] )
param = name [ "=" [ value ] ]
name = token
value = ( token | quoted-string )
token = 1*<any char except "=", ",", ";", <"> and
white space>
quoted-string = <"> *( text | quoted-char ) <">
text = any char except <">
quoted-char = "\" char
Any amount of white space is allowed between any part of the
header, element or param and is ignored. A missing value in any
element or param will be stored as the empty {@link String};
if the "=" is also missing null will be stored instead.
This class represents an individual header element, containing
both a name/value pair (value may be null) and optionally
a set of additional parameters.
|
Fields Summary |
---|
private final String | name | private final String | value | private final NameValuePair[] | parameters |
Constructors Summary |
---|
public BasicHeaderElement(String name, String value, NameValuePair[] parameters)Constructor with name, value and parameters.
super();
if (name == null) {
throw new IllegalArgumentException("Name may not be null");
}
this.name = name;
this.value = value;
if (parameters != null) {
this.parameters = parameters;
} else {
this.parameters = new NameValuePair[] {};
}
| public BasicHeaderElement(String name, String value)Constructor with name and value.
this(name, value, null);
|
Methods Summary |
---|
public java.lang.Object | clone()
// parameters array is considered immutable
// no need to make a copy of it
return super.clone();
| public boolean | equals(java.lang.Object object)
if (object == null) return false;
if (this == object) return true;
if (object instanceof HeaderElement) {
BasicHeaderElement that = (BasicHeaderElement) object;
return this.name.equals(that.name)
&& LangUtils.equals(this.value, that.value)
&& LangUtils.equals(this.parameters, that.parameters);
} else {
return false;
}
| public java.lang.String | getName()Returns the name.
return this.name;
| public org.apache.http.NameValuePair | getParameter(int index)Obtains the parameter with the given index.
// ArrayIndexOutOfBoundsException is appropriate
return this.parameters[index];
| public org.apache.http.NameValuePair | getParameterByName(java.lang.String name)Returns parameter with the given name, if found. Otherwise null
is returned
if (name == null) {
throw new IllegalArgumentException("Name may not be null");
}
NameValuePair found = null;
for (int i = 0; i < this.parameters.length; i++) {
NameValuePair current = this.parameters[ i ];
if (current.getName().equalsIgnoreCase(name)) {
found = current;
break;
}
}
return found;
| public int | getParameterCount()Obtains the number of parameters.
return this.parameters.length;
| public org.apache.http.NameValuePair[] | getParameters()Get parameters, if any.
The returned array is created for each invocation and can
be modified by the caller without affecting this header element.
return (NameValuePair[])this.parameters.clone();
| public java.lang.String | getValue()Returns the value.
return this.value;
| public int | hashCode()
int hash = LangUtils.HASH_SEED;
hash = LangUtils.hashCode(hash, this.name);
hash = LangUtils.hashCode(hash, this.value);
for (int i = 0; i < this.parameters.length; i++) {
hash = LangUtils.hashCode(hash, this.parameters[i]);
}
return hash;
| public java.lang.String | toString()
CharArrayBuffer buffer = new CharArrayBuffer(64);
buffer.append(this.name);
if (this.value != null) {
buffer.append("=");
buffer.append(this.value);
}
for (int i = 0; i < this.parameters.length; i++) {
buffer.append("; ");
buffer.append(this.parameters[i]);
}
return buffer.toString();
|
|