Package org.apache.tomcat.util.http
Class MimeHeaders
java.lang.Object
org.apache.tomcat.util.http.MimeHeaders
Memory-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:
- one-buffer parsing - for http (other protocols don't need that)
- remove unused methods
- External enumerations, with 0 GC.
- use HeaderName ID
- Author:
- dac@eng.sun.com, James Todd [gonzo@eng.sun.com], Costin Manolache, kevin seguin
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Initial size - should be == average number of headers per request -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddValue
(byte[] b, int startN, int len) Create a new named header using un-translated byte[].Create a new named header , return the MessageBytes container for the new valuevoid
clear()
Clears all header fields.void
duplicate
(MimeHeaders source) int
findHeader
(String name, int starting) Find the index of a header with the given name.getName
(int n) getUniqueValue
(String name) Finds and returns a unique header field with the given name.getValue
(int n) Finds and returns a header field with the given name.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
(String name) Removes a header field with the specified name.void
setLimit
(int limit) Set limit on the number of header fields.Allow "set" operations, which removes all current values for this header.int
size()
toString()
EXPENSIVE!!!
-
Field Details
-
DEFAULT_HEADER_SIZE
public static final int DEFAULT_HEADER_SIZEInitial size - should be == average number of headers per requestTODO make it configurable (fine-tuning of web-apps)
- See Also:
-
-
Constructor Details
-
MimeHeaders
public MimeHeaders()Creates a new MimeHeaders object using a default buffer size.
-
-
Method Details
-
setLimit
public void setLimit(int limit) Set limit on the number of header fields.- Parameters:
limit
- The new limit
-
recycle
public void recycle()Clears all header fields. -
clear
public void clear()Clears all header fields. -
toString
EXPENSIVE!!! only for debugging. -
duplicate
- Throws:
IOException
-
size
public int size()- Returns:
- the current number of header fields.
-
getName
- 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.
-
getValue
- 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.
-
findHeader
Find the index of a header with the given name.- Parameters:
name
- The header namestarting
- Index on which to start looking- Returns:
- the header index
-
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
-
values
-
addValue
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
-
addValue
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 bytesstartN
- Offsetlen
- Length- Returns:
- the message bytes container for the value
-
setValue
Allow "set" operations, which removes all current values for this header.- Parameters:
name
- The header name- Returns:
- the message bytes container for the value
-
getValue
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
-
getUniqueValue
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 anIllegalArgumentException
is thrown.- Parameters:
name
- The header name- Returns:
- the value if unique
- Throws:
IllegalArgumentException
- if the header has multiple values
-
getHeader
-
removeHeader
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
-
removeHeader
public void removeHeader(int idx) Reset, move to the end and then reduce count by 1.- Parameters:
idx
- the index of the header to remove.
-