public class MimeHeaders
extends java.lang.Object
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 |
|---|---|
static int |
DEFAULT_HEADER_SIZE
Initial size - should be == average number of headers per request
|
| Constructor and Description |
|---|
MimeHeaders()
Creates a new MimeHeaders object using a default buffer size.
|
| Modifier and Type | Method and Description |
|---|---|
MessageBytes |
addValue(byte[] b,
int startN,
int len)
Create a new named header using un-translated byte[].
|
MessageBytes |
addValue(java.lang.String name)
Create a new named header , return the MessageBytes container for the new value
|
void |
clear()
Deprecated.
|
void |
duplicate(MimeHeaders source) |
int |
findHeader(java.lang.String name,
int starting)
Find the index of a header with the given name.
|
java.lang.String |
getHeader(java.lang.String name) |
MessageBytes |
getName(int n) |
MessageBytes |
getUniqueValue(java.lang.String name)
Finds and returns a unique header field with the given name.
|
MessageBytes |
getValue(int n) |
MessageBytes |
getValue(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.
|
void |
recycle()
Clears all header fields.
|
void |
removeHeader(int idx)
Reset, move to the end and then reduce count by 1.
|
void |
removeHeader(java.lang.String name)
Removes a header field with the specified name.
|
void |
setLimit(int limit)
Set limit on the number of header fields.
|
MessageBytes |
setValue(java.lang.String name)
Allow "set" operations, which removes all current values for this header.
|
int |
size() |
java.lang.String |
toString() |
java.util.Enumeration<java.lang.String> |
values(java.lang.String name) |
public static final int DEFAULT_HEADER_SIZE
public MimeHeaders()
public void setLimit(int limit)
limit - The new limitpublic void recycle()
@Deprecated public void clear()
public java.lang.String toString()
toString in class java.lang.Objectpublic void duplicate(MimeHeaders source) throws java.io.IOException
java.io.IOExceptionpublic int size()
public MessageBytes getName(int n)
n - The header indexpublic MessageBytes getValue(int n)
n - The header indexpublic int findHeader(java.lang.String name,
int starting)
name - The header namestarting - Index on which to start lookingpublic java.util.Enumeration<java.lang.String> names()
public java.util.Enumeration<java.lang.String> values(java.lang.String name)
public MessageBytes addValue(java.lang.String name)
name - The header namepublic MessageBytes addValue(byte[] b, int startN, int len)
b - The header name bytesstartN - Offsetlen - Lengthpublic MessageBytes setValue(java.lang.String name)
name - The header namepublic MessageBytes getValue(java.lang.String name)
name - The header namepublic MessageBytes getUniqueValue(java.lang.String name)
IllegalArgumentException is thrown.name - The header namejava.lang.IllegalArgumentException - if the header has multiple valuespublic java.lang.String getHeader(java.lang.String name)
public void removeHeader(java.lang.String name)
name - the name of the header field to be removedpublic void removeHeader(int idx)
idx - the index of the header to remove.Copyright © 2000-2024 Apache Software Foundation.
Apache Tomcat, Tomcat, Apache, the Apache Tomcat logo and the Apache logo are either registered trademarks or trademarks of the Apache Software Foundation.