Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.http.util

public Class MimeHeaders

Additional top-level classes in compilation unit: BaseIterator, NamesIterator, ValuesIterator, MimeHeaderField.

extends Object
Class Inheritance
Imports
java.util.Arrays, .Iterator, org.glassfish.grizzly.Buffer

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

Authors
[email protected], James Todd [[email protected]], Costin Manolache, kevin seguin

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class

Field Summary

Modifier and TypeField 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 XXX make it configurable ( fine-tuning of web-apps )

private MimeHeaderField[]
headers

The header fields.

private static final String[]
protected int
private boolean
public static final int
public static final int
private int
private final Iterable<String>
namesIterable

The header names Iterable.

public static DataChunk

Constructor Summary

AccessConstructor and Description
public
MimeHeaders()

Creates a new MimeHeaders object using a default buffer size.

Method Summary

Modifier and TypeMethod and Description
public DataChunk
addValue(String name)

Create a new named header , return the MessageBytes container for the new value

public DataChunk
addValue(final Header header)

Create a new named header , return the MessageBytes container for the new value

public DataChunk
addValue(final byte[] buffer, final int startN, final int len)

Create a new named header using un-translated byte[].

public DataChunk
addValue(final Buffer buffer, final int startN, final int len)

Create a new named header using un-translated Buffer.

public void
clear()

Clears all header fields.

public boolean
contains(final Header header)

public boolean
contains(final String header)

private static void
public void
copyFrom(final MimeHeaders source)

private MimeHeaderField
createHeader()

Adds a partially constructed field to the header.

public String
public String
getHeader(final Header header)

public int
public DataChunk
getName(int n)

Returns the Nth header name, or null if there is no such header.

public DataChunk
getValue(int n)

Returns the Nth header value, or null if there is no such header.

public DataChunk
getValue(String name)

Finds and returns a header field with the given name.

public DataChunk
getValue(final Header header)

Finds and returns a header field with the given name.

public int
indexOf(String name, int fromIndex)

Find the index of a header with the given name.

public int
indexOf(final Header header, final int fromIndex)

Find the index of a header with the given name.

public boolean

Returns:

the header's "serialized" flag value.
isSerialized
(int
the header index
n
)

Get the header's "serialized" flag.

private boolean
isValidName(final String name)

private boolean
isValidName(final Header name)

private boolean
isValidName(final byte[] name)

private boolean
isValidName(final Buffer name)

public void
mark()

public Iterable<String>
names()

Returns an enumeration of strings representing the header field names.

public void
recycle()

Clears all header fields.

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(final Header header)

public void
removeHeader(final String
The name of the headers to be removed
name
,
final String
The string to check the header values against
str
)

Removes the headers with the given name whose values contain the given string.

pack-priv void
removeHeader(int
the index of the header to remove.
idx
)

reset and swap with last header

public void
removeHeaderMatches(final String
The name of the headers to be removed
name
,
final String
The regex string to check the header values against
regex
)

Removes the headers with the given name whose values contain the given string.

public void
removeHeaderMatches(final Header
The name of the Headers to be removed
header
,
final String
The regex string to check the header values against
regex
)

Removes the headers with the given name whose values contain the given string.

public void
setMaxNumHeaders(int maxNumHeaders)

public boolean

Returns:

the old header "serialized" flag value.
setSerialized
(int
the header index
n
,
boolean
the new value
newValue
)

Set the header's "serialized" flag.

public DataChunk
setValue(final String name)

Allow "set" operations - return a DataChunk container for the header value ( existing header or new if this .

public DataChunk
setValue(final Header header)

Allow "set" operations - return a DataChunk container for the header value ( existing header or new if this .

public int
size()

Returns the current number of header fields.

public String
toString()

Overrides java.lang.Object.toString.

EXPENSIVE!!!

public Iterable<String>
public int
public Iterable<String>
trailerValues(final String name)

public Iterable<String>
trailerValues(final Header name)

public Iterable<String>
values(final String name)

public Iterable<String>
values(final Header name)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

countback to summary
private int count

The current number of header fields.

DEFAULT_HEADER_SIZEback to summary
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 )

headersback to summary
private MimeHeaderField[] headers

The header fields.

INVALID_TRAILER_NAMESback to summary
private static final String[] INVALID_TRAILER_NAMES
markback to summary
protected int mark
markedback to summary
private boolean marked
MAX_NUM_HEADERS_DEFAULTback to summary
public static final int MAX_NUM_HEADERS_DEFAULT
MAX_NUM_HEADERS_UNBOUNDEDback to summary
public static final int MAX_NUM_HEADERS_UNBOUNDED
maxNumHeadersback to summary
private int maxNumHeaders
namesIterableback to summary
private final Iterable<String> namesIterable

The header names Iterable.

NOOP_CHUNKback to summary
public static DataChunk NOOP_CHUNK

Constructor Detail

MimeHeadersback to summary
public MimeHeaders()

Creates a new MimeHeaders object using a default buffer size.

Method Detail

addValueback to summary
public DataChunk addValue(String name)

Create a new named header , return the MessageBytes container for the new value

addValueback to summary
public DataChunk addValue(final Header header)

Create a new named header , return the MessageBytes container for the new value

addValueback to summary
public DataChunk addValue(final byte[] buffer, final int startN, final int len)

Create a new named header using un-translated byte[]. The conversion to chars can be delayed until encoding is known.

addValueback to summary
public DataChunk addValue(final Buffer buffer, final int startN, final int len)

Create a new named header using un-translated Buffer. The conversion to chars can be delayed until encoding is known.

clearback to summary
public void clear()

Clears all header fields.

containsback to summary
public boolean contains(final Header header)
containsback to summary
public boolean contains(final String header)
copyBufferChunkback to summary
private static void copyBufferChunk(DataChunk source, DataChunk dest)
copyFromback to summary
public void copyFrom(final MimeHeaders source)
createHeaderback to summary
private MimeHeaderField createHeader()

Adds a partially constructed field to the header. This field has not had its name or value initialized.

getHeaderback to summary
public String getHeader(String name)
getHeaderback to summary
public String getHeader(final Header header)
getMaxNumHeadersback to summary
public int getMaxNumHeaders()
Annotations
@SuppressWarnings:unused
getNameback to summary
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.

getValueback to summary
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.

getValueback to summary
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.

getValueback to summary
public DataChunk getValue(final 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.

indexOfback to summary
public int indexOf(String name, int fromIndex)

Find the index of a header with the given name.

indexOfback to summary
public int indexOf(final Header header, final int fromIndex)

Find the index of a header with the given name.

isSerializedback to summary
public boolean isSerialized(int n)

Get the header's "serialized" flag.

Parameters
n:int

the header index

Returns:boolean

the header's "serialized" flag value.

isValidNameback to summary
private boolean isValidName(final String name)
isValidNameback to summary
private boolean isValidName(final Header name)
isValidNameback to summary
private boolean isValidName(final byte[] name)
isValidNameback to summary
private boolean isValidName(final Buffer name)
markback to summary
public void mark()
namesback to summary
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.

recycleback to summary
public void recycle()

Clears all header fields.

removeHeaderback 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.

Parameters
name:String

the name of the header field to be removed

removeHeaderback to summary
public void removeHeader(final Header header)
removeHeaderback to summary
public void removeHeader(final String name, final String str)

Removes the headers with the given name whose values contain the given string.

Parameters
name:String

The name of the headers to be removed

str:String

The string to check the header values against

Annotations
@SuppressWarnings:UnusedDeclaration
removeHeaderback to summary
pack-priv void removeHeader(int idx)

reset and swap with last header

Parameters
idx:int

the index of the header to remove.

removeHeaderMatchesback to summary
public void removeHeaderMatches(final String name, final String regex)

Removes the headers with the given name whose values contain the given string.

Parameters
name:String

The name of the headers to be removed

regex:String

The regex string to check the header values against

Annotations
@SuppressWarnings:UnusedDeclaration
removeHeaderMatchesback to summary
public void removeHeaderMatches(final Header header, final String regex)

Removes the headers with the given name whose values contain the given string.

Parameters
header:Header

The name of the Headers to be removed

regex:String

The regex string to check the header values against

setMaxNumHeadersback to summary
public void setMaxNumHeaders(int maxNumHeaders)
setSerializedback to summary
public boolean setSerialized(int n, boolean newValue)

Set the header's "serialized" flag.

Parameters
n:int

the header index

newValue:boolean

the new value

Returns:boolean

the old header "serialized" flag value.

setValueback to summary
public DataChunk setValue(final String name)

Allow "set" operations - return a DataChunk container for the header value ( existing header or new if this .

setValueback to summary
public DataChunk setValue(final Header header)

Allow "set" operations - return a DataChunk container for the header value ( existing header or new if this .

sizeback to summary
public int size()

Returns the current number of header fields.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

EXPENSIVE!!! only for debugging.

Annotations
@Override
trailerNamesback to summary
public Iterable<String> trailerNames()
trailerSizeback to summary
public int trailerSize()
trailerValuesback to summary
public Iterable<String> trailerValues(final String name)
trailerValuesback to summary
public Iterable<String> trailerValues(final Header name)
Annotations
@SuppressWarnings:unused
valuesback to summary
public Iterable<String> values(final String name)
valuesback to summary
public Iterable<String> values(final Header name)
org.glassfish.grizzly.http.util back to summary

public Class MimeHeaders.MaxHeaderCountExceededException

extends IllegalStateException
Class Inheritance

Constructor Summary

AccessConstructor and Description
public

Constructor Detail

MaxHeaderCountExceededExceptionback to summary
public MaxHeaderCountExceededException()