Additional top-level classes in compilation unit: NamesEnumerator, ValuesEnumerator, MimeHeaderField.
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.
This class is used to contain standard internet message headers, used for SMTP (RFC822) and HTTP (RFC2068) messages as well as for MIME (RFC 2045) applications such as transferring typed data and grouping related items in multipart message bodies.
Message headers, as specified in RFC822, include a field name and a field body. Order has no semantic significance, and several fields with the same name may exist. However, most fields do not (and should not) exist more than once in a header.
Many kinds of field body must conform to a specified syntax, including the standard parenthesized comment syntax. This class supports only two simple syntaxes, for dates and integers.
When processing headers, care must be taken to handle the case of multiple same-name fields correctly. The values of such fields are only available as strings. They may be accessed by index (treating the header as an array of fields), or by name (returning an array of string values).
Headers are first parsed and stored in the order they are received. This is based on the fact that most servlets will not directly access all headers, and most headers are single-valued. (the alternative - a hash or similar data structure - will add an overhead that is not needed in most cases)
Apache seems to be using a similar method for storing and manipulating headers.
| Modifier and Type | Field and Description |
|---|---|
| private int | count
The current number of header fields. |
| public static final int | DEFAULT_HEADER_SIZE
Initial size - should be == average number of headers per request |
| private MimeHeaderField[] | headers
The header fields. |
| private int | limit
The limit on the number of header fields. |
| private static final StringManager |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public MessageBytes | |
| public MessageBytes | Returns: the message bytes container for the valueThe header name bytes b, int Offset startN, int Length len)Create a new named header using un-translated byte[]. |
| public void | |
| private MimeHeaderField | |
| public void | |
| public int | Returns: the header indexThe header name name, int Index on which to start looking starting)Find the index of a header with the given name. |
| public String | |
| public MessageBytes | Returns: the Nth header name, or null if there is no such header. This may be used to iterate through all header fields.The header index n)
|
| public MessageBytes | Returns: the value if uniqueThe header name name)Finds and returns a unique header field with the given name. |
| public MessageBytes | Returns: the Nth header value, or null if there is no such header. This may be used to iterate through all header fields.The header index n)
|
| public MessageBytes | |
| public Enumeration | Returns: the enumerationReturns an enumeration of strings representing the header field names. |
| public void | |
| public void | removeHeader(String
the name of the header field to be removed name)Removes a header field with the specified name. |
| public void | removeHeader(int
the index of the header to remove. idx)Reset, move to the end and then reduce count by 1. |
| public void | |
| public MessageBytes | |
| public int | |
| public String | |
| public Enumeration |
| count | back to summary |
|---|---|
| private int count The current number of header fields. | |
| DEFAULT_HEADER_SIZE | back to summary |
|---|---|
| public static final int DEFAULT_HEADER_SIZE Initial size - should be == average number of headers per request | |
| headers | back to summary |
|---|---|
| private MimeHeaderField[] headers The header fields. | |
| limit | back to summary |
|---|---|
| private int limit The limit on the number of header fields. | |
| sm | back to summary |
|---|---|
| private static final StringManager sm | |
| MimeHeaders | back to summary |
|---|---|
| public MimeHeaders() Creates a new MimeHeaders object using a default buffer size. | |
| addValue | back to summary |
|---|---|
| public MessageBytes addValue(String name) Create a new named header , return the MessageBytes container for the new value
| |
| addValue | back to summary |
|---|---|
| public 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.
| |
| clear | back to summary |
|---|---|
| public void clear()
Deprecated
| |
| createHeader | back to summary |
|---|---|
| private MimeHeaderField createHeader() Adds a partially constructed field to the header. This field has not had its name or value initialized. | |
| duplicate | back to summary |
|---|---|
| public void duplicate(MimeHeaders source) throws IOException | |
| findHeader | back to summary |
|---|---|
| public int findHeader(String name, int starting) Find the index of a header with the given name.
| |
| getHeader | back to summary |
|---|---|
| public String getHeader(String name) | |
| getName | back to summary |
|---|---|
public MessageBytes getName(int n)
| |
| getUniqueValue | back to summary |
|---|---|
| public MessageBytes getUniqueValue(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
| |
| getValue | back to summary |
|---|---|
public MessageBytes getValue(int n)
| |
| getValue | back to summary |
|---|---|
| public MessageBytes getValue(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.
| |
| names | back to summary |
|---|---|
| public Enumeration 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.
| |
| recycle | back to summary |
|---|---|
| public void recycle() Clears all header fields. | |
| removeHeader | back to summary |
|---|---|
| public void removeHeader(String name) Removes a header field with the specified name. Does nothing if such a field could not be found.
| |
| removeHeader | back to summary |
|---|---|
| public void removeHeader(int idx) Reset, move to the end and then reduce count by 1.
| |
| setLimit | back to summary |
|---|---|
| public void setLimit(int limit) Set limit on the number of header fields.
| |
| setValue | back to summary |
|---|---|
| public MessageBytes setValue(String name) Allow "set" operations, which removes all current values for this header.
| |
| size | back to summary |
|---|---|
public int size()
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| values | back to summary |
|---|---|
| public Enumeration | |