Methods Summary |
---|
public org.apache.tomcat.util.buf.MessageBytes | addValue(java.lang.String name)Create a new named header , return the MessageBytes
container for the new value
MimeHeaderField mh = createHeader();
mh.getName().setString(name);
return mh.getValue();
|
public org.apache.tomcat.util.buf.MessageBytes | addValue(byte[] b, int startN, int len)Create a new named header using un-translated byte[].
The conversion to chars can be delayed until
encoding is known.
MimeHeaderField mhf=createHeader();
mhf.getName().setBytes(b, startN, len);
return mhf.getValue();
|
public org.apache.tomcat.util.buf.MessageBytes | addValue(char[] c, int startN, int len)Create a new named header using translated char[].
MimeHeaderField mhf=createHeader();
mhf.getName().setChars(c, startN, len);
return mhf.getValue();
|
public void | clear()Clears all header fields.
for (int i = 0; i < count; i++) {
headers[i].recycle();
}
count = 0;
|
private org.apache.tomcat.util.http.MimeHeaderField | createHeader()Adds a partially constructed field to the header. This
field has not had its name or value initialized.
MimeHeaderField mh;
int len = headers.length;
if (count >= len) {
// expand header list array
MimeHeaderField tmp[] = new MimeHeaderField[count * 2];
System.arraycopy(headers, 0, tmp, 0, len);
headers = tmp;
}
if ((mh = headers[count]) == null) {
headers[count] = mh = new MimeHeaderField();
}
count++;
return mh;
|
public int | findHeader(java.lang.String name, int starting)Find the index of a header with the given name.
// We can use a hash - but it's not clear how much
// benefit you can get - there is an overhead
// and the number of headers is small (4-5 ?)
// Another problem is that we'll pay the overhead
// of constructing the hashtable
// A custom search tree may be better
for (int i = starting; i < count; i++) {
if (headers[i].getName().equalsIgnoreCase(name)) {
return i;
}
}
return -1;
|
public java.lang.String | getHeader(java.lang.String name)
MessageBytes mh = getValue(name);
return mh != null ? mh.toString() : null;
|
public org.apache.tomcat.util.buf.MessageBytes | getName(int n)Returns the Nth header name, or null if there is no such header.
This may be used to iterate through all header fields.
return n >= 0 && n < count ? headers[n].getName() : null;
|
public org.apache.tomcat.util.buf.MessageBytes | getUniqueValue(java.lang.String name)Finds and returns a unique header field with the given name. If no such
field exists, null is returned. If the specified header field is not
unique then an {@link IllegalArgumentException} is thrown.
MessageBytes result = null;
for (int i = 0; i < count; i++) {
if (headers[i].getName().equalsIgnoreCase(name)) {
if (result == null) {
result = headers[i].getValue();
} else {
throw new IllegalArgumentException();
}
}
}
return result;
|
public org.apache.tomcat.util.buf.MessageBytes | getValue(java.lang.String name)Finds and returns a header field with the given name. If no such
field exists, null is returned. If more than one such field is
in the header, an arbitrary one is returned.
for (int i = 0; i < count; i++) {
if (headers[i].getName().equalsIgnoreCase(name)) {
return headers[i].getValue();
}
}
return null;
|
public org.apache.tomcat.util.buf.MessageBytes | getValue(int n)Returns the Nth header value, or null if there is no such header.
This may be used to iterate through all header fields.
return n >= 0 && n < count ? headers[n].getValue() : null;
|
public java.util.Enumeration | names()Returns an enumeration of strings representing the header field names.
Field names may appear multiple times in this enumeration, indicating
that multiple fields with that name exist in this header.
return new NamesEnumerator(this);
|
public void | recycle()Clears all header fields.
clear();
|
public void | removeHeader(java.lang.String name)Removes a header field with the specified name. Does nothing
if such a field could not be found.
// XXX
// warning: rather sticky code; heavily tuned
for (int i = 0; i < count; i++) {
if (headers[i].getName().equalsIgnoreCase(name)) {
removeHeader(i--);
}
}
|
private void | removeHeader(int idx)reset and swap with last header
MimeHeaderField mh = headers[idx];
mh.recycle();
headers[idx] = headers[count - 1];
headers[count - 1] = mh;
count--;
|
public org.apache.tomcat.util.buf.MessageBytes | setValue(java.lang.String name)Allow "set" operations -
return a MessageBytes container for the
header value ( existing header or new
if this .
for ( int i = 0; i < count; i++ ) {
if(headers[i].getName().equalsIgnoreCase(name)) {
for ( int j=i+1; j < count; j++ ) {
if(headers[j].getName().equalsIgnoreCase(name)) {
removeHeader(j--);
}
}
return headers[i].getValue();
}
}
MimeHeaderField mh = createHeader();
mh.getName().setString(name);
return mh.getValue();
|
public int | size()Returns the current number of header fields.
return count;
|
public java.lang.String | toString()EXPENSIVE!!! only for debugging.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
pw.println("=== MimeHeaders ===");
Enumeration e = names();
while (e.hasMoreElements()) {
String n = (String)e.nextElement();
pw.println(n + " = " + getHeader(n));
}
return sw.toString();
|
public java.util.Enumeration | values(java.lang.String name)
return new ValuesEnumerator(this, name);
|