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

public Class ContentType

extends Object
Class Inheritance
Known Direct Subclasses
org.glassfish.grizzly.http.util.ContentType.SettableContentType
Static Imports
org.glassfish.grizzly.http.util.HttpCodecUtils.EMPTY_ARRAY, .HttpCodecUtils.toCheckedByteArray

This class serves as a Content-Type holder, plus it implements useful utility methods to work with content-type.
Author
Alexey Stashok

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private byte[]
private String
private static final byte[]
private static final String
private String
private byte[]
private boolean
private boolean
private int
private String
private String
private String

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
ContentType(final String contentType)

Method Summary

Modifier and TypeMethod and Description
private void
checkArray(final int len)

public static byte[]

Returns:

a content-type array, composed of the mime-type represented by a byte array and a charset attribute value, represented by a String
compose
(final byte[]
a mime-type part of the content-type (doesn't contain charset attribute)
mimeType
,
final String
charset attribute value
charset
)

Composes a content-type array, based on the mime-type represented by a byte array and a charset attribute value, represented by a String.

public String
get()

Returns: the content type of this HTTP message.

public int

Returns:

the data length within the array returned by getByteArray()
getArrayLen
()

Used in conjunction with getByteArray().

public byte[]
getByteArray()

Returns: the byte array representation of the content-type

public String
getCharacterEncoding()

Returns: the character encoding (the content-type's charset attribute value)

public static String

Returns:

the contentType's charset attribute value
getCharsetFromContentType
(String
a content type header
contentType
)

Parse the character encoding from the specified content type header.

public String

Returns:

the mime-type part of the content-type (the part without charset attribute)
getMimeType
()

Returns the mime-type part of the content-type (the part without charset attribute).

public boolean
isMimeTypeSet()

Returns: true if mime-type is set, or false otherwise

public boolean
isSet()

Returns: true if either mime-type or character encoding is set, or false otherwise

public static ContentType

Returns:

a ContentType wrapper over a String content-type representation
newContentType
(final String
String content-type representation
contentType
)

Creates a ContentType wrapper over a String content-type representation.

public static ContentType

Returns:

a ContentType wrapper over the passed mime-type and character encoding
newContentType
(final String
String mimeType-type representation (like "text/plain", "text/html", etc), which doesn't contain charset information
mimeType
,
final String
charset attribute to be used with the mime-type
characterEncoding
)

Creates a ContentType wrapper over the passed mime-type and character encoding.

public static ContentType.SettableContentType
newSettableContentType()

Returns: SettableContentType, the mutable ContentType representation.

private void
parse()

Parse the unparsedContentType and splitting it into mime-type and character encoding.

public ContentType

Returns:

this ContentType
prepare
()

Prepare the ContentType for the serialization.

public static byte[]

Returns:

a new array, which represents the same content-type as a given one, but without charset attribute
removeCharset
(final byte[]
the content-type represented by an array
contentType
)

Removes the charset attribute from the content-type represented by an array.

protected void
reset()

Resets the ContentType state.

public void
serializeToDataChunk(final DataChunk dc)

Serializes this ContentType value into a passed DataChunk.

protected void
set(final String
the content type
contentType
)

Sets the content type.

protected void
set(final ContentType
the content type
contentType
)

Sets the content type.

protected void
setCharacterEncoding(final String
the character encoding (the content-type's charset attribute value)
charset
)

Sets the the character encoding (the content-type's charset attribute value).

protected void
setMimeType(final String
the mime-type part of the content-type (the part without charset attribute)
mimeType
)

Sets the mime-type part of the content-type (the part without charset attribute).

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

arrayback to summary
private byte[] array
characterEncodingback to summary
private String characterEncoding
CHARSET_BYTESback to summary
private static final byte[] CHARSET_BYTES
CHARSET_STRINGback to summary
private static final String CHARSET_STRING
compiledContentTypeback to summary
private String compiledContentType
compiledContentTypeArrayback to summary
private byte[] compiledContentTypeArray
isCharsetSetback to summary
private boolean isCharsetSet
isParsedback to summary
private boolean isParsed
lenback to summary
private int len
mimeTypeback to summary
private String mimeType
quotedCharsetValueback to summary
private String quotedCharsetValue
unparsedContentTypeback to summary
private String unparsedContentType

Constructor Detail

ContentTypeback to summary
pack-priv ContentType()
ContentTypeback to summary
pack-priv ContentType(final String contentType)

Method Detail

checkArrayback to summary
private void checkArray(final int len)
composeback to summary
public static byte[] compose(final byte[] mimeType, final String charset)

Composes a content-type array, based on the mime-type represented by a byte array and a charset attribute value, represented by a String.

Parameters
mimeType:byte[]

a mime-type part of the content-type (doesn't contain charset attribute)

charset:String

charset attribute value

Returns:byte[]

a content-type array, composed of the mime-type represented by a byte array and a charset attribute value, represented by a String

getback to summary
public String get()
Returns:String

the content type of this HTTP message.

getArrayLenback to summary
public int getArrayLen()

Used in conjunction with getByteArray(). The array returned by the aforementioned method may be larger than the data contained therein. This method will return the proper data length.

Returns:int

the data length within the array returned by getByteArray()

getByteArrayback to summary
public byte[] getByteArray()
Returns:byte[]

the byte array representation of the content-type

getCharacterEncodingback to summary
public String getCharacterEncoding()
Returns:String

the character encoding (the content-type's charset attribute value)

getCharsetFromContentTypeback to summary
public static String getCharsetFromContentType(String contentType)

Parse the character encoding from the specified content type header. If the content type is null, or there is no explicit character encoding, null is returned.

Parameters
contentType:String

a content type header

Returns:String

the contentType's charset attribute value

getMimeTypeback to summary
public String getMimeType()

Returns the mime-type part of the content-type (the part without charset attribute).

Returns:String

the mime-type part of the content-type (the part without charset attribute)

isMimeTypeSetback to summary
public boolean isMimeTypeSet()
Returns:boolean

true if mime-type is set, or false otherwise

isSetback to summary
public boolean isSet()
Returns:boolean

true if either mime-type or character encoding is set, or false otherwise

newContentTypeback to summary
public static ContentType newContentType(final String contentType)

Creates a ContentType wrapper over a String content-type representation.

Parameters
contentType:String

String content-type representation

Returns:ContentType

a ContentType wrapper over a String content-type representation

newContentTypeback to summary
public static ContentType newContentType(final String mimeType, final String characterEncoding)

Creates a ContentType wrapper over the passed mime-type and character encoding.

Parameters
mimeType:String

String mimeType-type representation (like "text/plain", "text/html", etc), which doesn't contain charset information

characterEncoding:String

charset attribute to be used with the mime-type

Returns:ContentType

a ContentType wrapper over the passed mime-type and character encoding

newSettableContentTypeback to summary
public static ContentType.SettableContentType newSettableContentType()
Returns:ContentType.SettableContentType

SettableContentType, the mutable ContentType representation.

parseback to summary
private void parse()

Parse the unparsedContentType and splitting it into mime-type and character encoding.

prepareback to summary
public ContentType prepare()

Prepare the ContentType for the serialization. This method might be particularly useful if we use the same ContentType over and over for different responses, so that the ContentType will not have to be parsed and prepared for each response separately.

Returns:ContentType

this ContentType

removeCharsetback to summary
public static byte[] removeCharset(final byte[] contentType)

Removes the charset attribute from the content-type represented by an array. The returned array will be completely independent of the source one.

Parameters
contentType:byte[]

the content-type represented by an array

Returns:byte[]

a new array, which represents the same content-type as a given one, but without charset attribute

resetback to summary
protected void reset()

Resets the ContentType state.

serializeToDataChunkback to summary
public void serializeToDataChunk(final DataChunk dc)

Serializes this ContentType value into a passed DataChunk.

Parameters
dc:DataChunk

DataChunk

setback to summary
protected void set(final String contentType)

Sets the content type. This method must preserve any charset that may already have been set via a call to request/response.setContentType(), request/response.setLocale(), or request/response.setCharacterEncoding().

Parameters
contentType:String

the content type

setback to summary
protected void set(final ContentType contentType)

Sets the content type. This method must preserve any charset that may already have been set via a call to request/response.setContentType(), request/response.setLocale(), or request/response.setCharacterEncoding(). This method copies the passed contentType state into this ContentType.

Parameters
contentType:ContentType

the content type

setCharacterEncodingback to summary
protected void setCharacterEncoding(final String charset)

Sets the the character encoding (the content-type's charset attribute value).

Parameters
charset:String

the character encoding (the content-type's charset attribute value)

setMimeTypeback to summary
protected void setMimeType(final String mimeType)

Sets the mime-type part of the content-type (the part without charset attribute).

Parameters
mimeType:String

the mime-type part of the content-type (the part without charset attribute)

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
org.glassfish.grizzly.http.util back to summary

public final Class ContentType.SettableContentType

extends ContentType
Class Inheritance

Mutable ContentType object.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
reset()

Overrides org.glassfish.grizzly.http.util.ContentType.reset.

Resets the ContentType state.

public void
set(final ContentType contentType)

Overrides org.glassfish.grizzly.http.util.ContentType.set.

Sets the content type.

public void
set(final String type)

Overrides org.glassfish.grizzly.http.util.ContentType.set.

Sets the content type.

public void
setCharacterEncoding(final String charset)

Overrides org.glassfish.grizzly.http.util.ContentType.setCharacterEncoding.

Sets the the character encoding (the content-type's charset attribute value).

public void
setMimeType(final String mimeType)

Overrides org.glassfish.grizzly.http.util.ContentType.setMimeType.

Sets the mime-type part of the content-type (the part without charset attribute).

Inherited from org.glassfish.grizzly.http.util.ContentType:
composegetgetArrayLengetByteArraygetCharacterEncodinggetCharsetFromContentTypegetMimeTypeisMimeTypeSetisSetnewContentTypenewContentTypenewSettableContentTypeprepareremoveCharsetserializeToDataChunktoString

Constructor Detail

SettableContentTypeback to summary
pack-priv SettableContentType()

Method Detail

resetback to summary
public void reset()

Overrides org.glassfish.grizzly.http.util.ContentType.reset.

Doc from org.glassfish.grizzly.http.util.ContentType.reset.

Resets the ContentType state.

Annotations
@Override
setback to summary
public void set(final ContentType contentType)

Overrides org.glassfish.grizzly.http.util.ContentType.set.

Doc from org.glassfish.grizzly.http.util.ContentType.set.

Sets the content type. This method must preserve any charset that may already have been set via a call to request/response.setContentType(), request/response.setLocale(), or request/response.setCharacterEncoding(). This method copies the passed contentType state into this ContentType.

Annotations
@Override
setback to summary
public void set(final String type)

Overrides org.glassfish.grizzly.http.util.ContentType.set.

Doc from org.glassfish.grizzly.http.util.ContentType.set.

Sets the content type. This method must preserve any charset that may already have been set via a call to request/response.setContentType(), request/response.setLocale(), or request/response.setCharacterEncoding().

Annotations
@Override
setCharacterEncodingback to summary
public void setCharacterEncoding(final String charset)

Overrides org.glassfish.grizzly.http.util.ContentType.setCharacterEncoding.

Doc from org.glassfish.grizzly.http.util.ContentType.setCharacterEncoding.

Sets the the character encoding (the content-type's charset attribute value).

Annotations
@Override
setMimeTypeback to summary
public void setMimeType(final String mimeType)

Overrides org.glassfish.grizzly.http.util.ContentType.setMimeType.

Doc from org.glassfish.grizzly.http.util.ContentType.setMimeType.

Sets the mime-type part of the content-type (the part without charset attribute).

Annotations
@Override