Package org.glassfish.grizzly.http.util
Class MimeHeaders
- java.lang.Object
-
- org.glassfish.grizzly.http.util.MimeHeaders
-
public class MimeHeaders extends Object
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 DataChunk 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_ DataChunk-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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classMimeHeaders.MaxHeaderCountExceededException
-
Field Summary
Fields 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 )protected intmarkstatic intMAX_NUM_HEADERS_DEFAULTstatic intMAX_NUM_HEADERS_UNBOUNDEDstatic DataChunkNOOP_CHUNK
-
Constructor Summary
Constructors Constructor Description MimeHeaders()Creates a new MimeHeaders object using a default buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DataChunkaddValue(byte[] buffer, int startN, int len)Create a new named header using un-translated byte[].DataChunkaddValue(String name)Create a new named header , return the MessageBytes container for the new valueDataChunkaddValue(org.glassfish.grizzly.Buffer buffer, int startN, int len)Create a new named header using un-translated Buffer.DataChunkaddValue(Header header)Create a new named header , return the MessageBytes container for the new valuevoidclear()Clears all header fields.booleancontains(String header)booleancontains(Header header)voidcopyFrom(MimeHeaders source)StringgetHeader(String name)StringgetHeader(Header header)intgetMaxNumHeaders()DataChunkgetName(int n)Returns the Nth header name, or null if there is no such header.DataChunkgetValue(int n)Returns the Nth header value, or null if there is no such header.DataChunkgetValue(String name)Finds and returns a header field with the given name.DataChunkgetValue(Header header)Finds and returns a header field with the given name.intindexOf(String name, int fromIndex)Find the index of a header with the given name.intindexOf(Header header, int fromIndex)Find the index of a header with the given name.booleanisSerialized(int n)Get the header's "serialized" flag.voidmark()Iterable<String>names()Returns an enumeration of strings representing the header field names.voidrecycle()Clears all header fields.voidremoveHeader(String name)Removes a header field with the specified name.voidremoveHeader(String name, String str)Removes the headers with the given name whose values contain the given string.voidremoveHeader(Header header)voidremoveHeaderMatches(String name, String regex)Removes the headers with the given name whose values contain the given string.voidremoveHeaderMatches(Header header, String regex)Removes the headers with the given name whose values contain the given string.voidsetMaxNumHeaders(int maxNumHeaders)booleansetSerialized(int n, boolean newValue)Set the header's "serialized" flag.DataChunksetValue(String name)Allow "set" operations - return a DataChunk container for the header value ( existing header or new if this .DataChunksetValue(Header header)Allow "set" operations - return a DataChunk container for the header value ( existing header or new if this .intsize()Returns the current number of header fields.StringtoString()EXPENSIVE!!! only for debugging.Iterable<String>trailerNames()inttrailerSize()Iterable<String>trailerValues(String name)Iterable<String>trailerValues(Header name)Iterable<String>values(String name)Iterable<String>values(Header name)
-
-
-
Field Detail
-
MAX_NUM_HEADERS_UNBOUNDED
public static final int MAX_NUM_HEADERS_UNBOUNDED
- See Also:
- Constant Field Values
-
MAX_NUM_HEADERS_DEFAULT
public static final int MAX_NUM_HEADERS_DEFAULT
- See Also:
- Constant Field Values
-
DEFAULT_HEADER_SIZE
public 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
-
NOOP_CHUNK
public static DataChunk NOOP_CHUNK
-
mark
protected int mark
-
-
Method Detail
-
mark
public void mark()
-
recycle
public void recycle()
Clears all header fields.
-
clear
public void clear()
Clears all header fields.
-
toString
public String toString()
EXPENSIVE!!! only for debugging.
-
copyFrom
public void copyFrom(MimeHeaders source)
-
size
public int size()
Returns the current number of header fields.
-
trailerSize
public int trailerSize()
-
getName
public DataChunk getName(int n)
Returns the Nth header name, or null if there is no such header. This may be used to iterate through all header fields.
-
getValue
public DataChunk getValue(int n)
Returns the Nth header value, or null if there is no such header. This may be used to iterate through all header fields.
-
isSerialized
public boolean isSerialized(int n)
Get the header's "serialized" flag.- Parameters:
n- the header index- Returns:
- the header's "serialized" flag value.
-
setSerialized
public boolean setSerialized(int n, boolean newValue)Set the header's "serialized" flag.- Parameters:
n- the header indexnewValue- the new value- Returns:
- the old header "serialized" flag value.
-
indexOf
public int indexOf(String name, int fromIndex)
Find the index of a header with the given name.
-
indexOf
public int indexOf(Header header, int fromIndex)
Find the index of a header with the given name.
-
contains
public boolean contains(Header header)
-
contains
public boolean contains(String header)
-
names
public Iterable<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.
-
addValue
public DataChunk addValue(String name)
Create a new named header , return the MessageBytes container for the new value
-
addValue
public DataChunk addValue(Header header)
Create a new named header , return the MessageBytes container for the new value
-
addValue
public DataChunk addValue(byte[] buffer, int startN, int len)
Create a new named header using un-translated byte[]. The conversion to chars can be delayed until encoding is known.
-
addValue
public DataChunk addValue(org.glassfish.grizzly.Buffer buffer, int startN, int len)
Create a new named header using un-translated Buffer. The conversion to chars can be delayed until encoding is known.
-
setValue
public DataChunk setValue(String name)
Allow "set" operations - return a DataChunk container for the header value ( existing header or new if this .
-
setValue
public DataChunk setValue(Header header)
Allow "set" operations - return a DataChunk container for the header value ( existing header or new if this .
-
getValue
public DataChunk 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.
-
getValue
public DataChunk getValue(Header header)
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.
-
removeHeader
public void removeHeader(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
-
removeHeader
public void removeHeader(Header header)
-
removeHeader
public void removeHeader(String name, String str)
Removes the headers with the given name whose values contain the given string.- Parameters:
name- The name of the headers to be removedstr- The string to check the header values against
-
removeHeaderMatches
public void removeHeaderMatches(String name, String regex)
Removes the headers with the given name whose values contain the given string.- Parameters:
name- The name of the headers to be removedregex- The regex string to check the header values against
-
removeHeaderMatches
public void removeHeaderMatches(Header header, String regex)
Removes the headers with the given name whose values contain the given string.- Parameters:
header- The name of theHeaders to be removedregex- The regex string to check the header values against
-
setMaxNumHeaders
public void setMaxNumHeaders(int maxNumHeaders)
-
getMaxNumHeaders
public int getMaxNumHeaders()
-
-