Package org.apache.tomcat.util.http
Class MimeHeaders
- java.lang.Object
- 
- org.apache.tomcat.util.http.MimeHeaders
 
- 
 public class MimeHeaders extends java.lang.ObjectMemory-efficient repository for Mime Headers. When the object is recycled, it will keep the allocated headers[] and all the MimeHeaderField - no GC is generated. For input headers it is possible to use the MessageByte for Fields - so no GC will be generated. The only garbage is generated when using the String for header names/values - this can't be avoided when the servlet calls header methods, but is easy to avoid inside tomcat. The goal is to use _only_ MessageByte-based Fields, and reduce to 0 the memory overhead of tomcat. TODO: XXX one-buffer parsing - for http ( other protocols don't need that ) XXX remove unused methods XXX External enumerations, with 0 GC. XXX use HeaderName ID- Author:
- dac@eng.sun.com, James Todd [gonzo@eng.sun.com], Costin Manolache, kevin seguin
 
- 
- 
Field SummaryFields Modifier and Type Field Description static intDEFAULT_HEADER_SIZEInitial size - should be == average number of headers per request XXX make it configurable ( fine-tuning of web-apps )
 - 
Constructor SummaryConstructors Constructor Description MimeHeaders()Creates a new MimeHeaders object using a default buffer size.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description MessageBytesaddValue(byte[] b, int startN, int len)Create a new named header using un-translated byte[].MessageBytesaddValue(java.lang.String name)Create a new named header , return the MessageBytes container for the new valuevoidclear()Clears all header fields.voidduplicate(MimeHeaders source)intfindHeader(java.lang.String name, int starting)Find the index of a header with the given name.java.lang.StringgetHeader(java.lang.String name)MessageBytesgetName(int n)MessageBytesgetUniqueValue(java.lang.String name)Finds and returns a unique header field with the given name.MessageBytesgetValue(int n)MessageBytesgetValue(java.lang.String name)Finds and returns a header field with the given name.java.util.Enumeration<java.lang.String>names()Returns an enumeration of strings representing the header field names.voidrecycle()Clears all header fields.voidremoveHeader(int idx)Reset, move to the end and then reduce count by 1.voidremoveHeader(java.lang.String name)Removes a header field with the specified name.voidsetLimit(int limit)Set limit on the number of header fields.MessageBytessetValue(java.lang.String name)Allow "set" operations, which removes all current values for this header.intsize()java.lang.StringtoString()EXPENSIVE!!!java.util.Enumeration<java.lang.String>values(java.lang.String name)
 
- 
- 
- 
Field Detail- 
DEFAULT_HEADER_SIZEpublic static final int DEFAULT_HEADER_SIZE Initial size - should be == average number of headers per request XXX make it configurable ( fine-tuning of web-apps )- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
setLimitpublic void setLimit(int limit) Set limit on the number of header fields.- Parameters:
- limit- The new limit
 
 - 
recyclepublic void recycle() Clears all header fields.
 - 
clearpublic void clear() Clears all header fields.
 - 
toStringpublic java.lang.String toString() EXPENSIVE!!! only for debugging.- Overrides:
- toStringin class- java.lang.Object
 
 - 
duplicatepublic void duplicate(MimeHeaders source) throws java.io.IOException - Throws:
- java.io.IOException
 
 - 
sizepublic int size() - Returns:
- the current number of header fields.
 
 - 
getNamepublic MessageBytes getName(int n) - Parameters:
- n- The header index
- Returns:
- the Nth header name, or null if there is no such header. This may be used to iterate through all header fields.
 
 - 
getValuepublic MessageBytes getValue(int n) - Parameters:
- n- The header index
- Returns:
- the Nth header value, or null if there is no such header. This may be used to iterate through all header fields.
 
 - 
findHeaderpublic int findHeader(java.lang.String name, int starting)Find the index of a header with the given name.- Parameters:
- name- The header name
- starting- Index on which to start looking
- Returns:
- the header index
 
 - 
namespublic java.util.Enumeration<java.lang.String> 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.- Returns:
- the enumeration
 
 - 
valuespublic java.util.Enumeration<java.lang.String> values(java.lang.String name) 
 - 
addValuepublic MessageBytes addValue(java.lang.String name) Create a new named header , return the MessageBytes container for the new value- Parameters:
- name- The header name
- Returns:
- the message bytes container for the value
 
 - 
addValuepublic 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.- Parameters:
- b- The header name bytes
- startN- Offset
- len- Length
- Returns:
- the message bytes container for the value
 
 - 
setValuepublic MessageBytes setValue(java.lang.String name) Allow "set" operations, which removes all current values for this header.- Parameters:
- name- The header name
- Returns:
- the message bytes container for the value
 
 - 
getValuepublic 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.- Parameters:
- name- The header name
- Returns:
- the value
 
 - 
getUniqueValuepublic 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 anIllegalArgumentExceptionis thrown.- Parameters:
- name- The header name
- Returns:
- the value if unique
- Throws:
- java.lang.IllegalArgumentException- if the header has multiple values
 
 - 
getHeaderpublic java.lang.String getHeader(java.lang.String name) 
 - 
removeHeaderpublic void removeHeader(java.lang.String name) Removes a header field with the specified name. Does nothing if such a field could not be found.- Parameters:
- name- the name of the header field to be removed
 
 - 
removeHeaderpublic void removeHeader(int idx) Reset, move to the end and then reduce count by 1.- Parameters:
- idx- the index of the header to remove.
 
 
- 
 
-