Method from org.apache.tomcat.util.http.MimeHeaders Detail: |
public MessageBytes addValue(String name) {
MimeHeaderField mh = createHeader();
mh.getName().setString(name);
return mh.getValue();
}
Create a new named header , return the MessageBytes
container for the new value |
public MessageBytes addValue(byte[] b,
int startN,
int len) {
MimeHeaderField mhf=createHeader();
mhf.getName().setBytes(b, startN, len);
return mhf.getValue();
}
Create a new named header using un-translated byte[].
The conversion to chars can be delayed until
encoding is known. |
public MessageBytes addValue(char[] c,
int startN,
int len) {
MimeHeaderField mhf=createHeader();
mhf.getName().setChars(c, startN, len);
return mhf.getValue();
}
Create a new named header using translated char[]. |
public void clear() {
for (int i = 0; i < count; i++) {
headers[i].recycle();
}
count = 0;
}
Clears all header fields. |
public int findHeader(String name,
int starting) {
// 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;
}
Find the index of a header with the given name. |
public String getHeader(String name) {
MessageBytes mh = getValue(name);
return mh != null ? mh.toString() : null;
}
|
public MessageBytes getName(int n) {
return n >= 0 && n < count ? headers[n].getName() : null;
}
Returns the Nth header name, or null if there is no such header.
This may be used to iterate through all header fields. |
public MessageBytes getUniqueValue(String name) {
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;
}
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 IllegalArgumentException is thrown. |
public MessageBytes getValue(int n) {
return n >= 0 && n < count ? headers[n].getValue() : null;
}
Returns the Nth header value, or null if there is no such header.
This may be used to iterate through all header fields. |
public MessageBytes getValue(String name) {
for (int i = 0; i < count; i++) {
if (headers[i].getName().equalsIgnoreCase(name)) {
return headers[i].getValue();
}
}
return null;
}
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. |
public Enumeration names() {
return new NamesEnumerator(this);
}
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. |
public void recycle() {
clear();
}
Clears all header fields. |
public void removeHeader(String name) {
// XXX
// warning: rather sticky code; heavily tuned
for (int i = 0; i < count; i++) {
if (headers[i].getName().equalsIgnoreCase(name)) {
removeHeader(i--);
}
}
}
Removes a header field with the specified name. Does nothing
if such a field could not be found. |
public MessageBytes setValue(String name) {
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();
}
Allow "set" operations -
return a MessageBytes container for the
header value ( existing header or new
if this . |
public int size() {
return count;
}
Returns the current number of header fields. |
public String toString() {
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();
}
EXPENSIVE!!! only for debugging. |
public Enumeration values(String name) {
return new ValuesEnumerator(this, name);
}
|