java.lang.Object
org.glassfish.grizzly.http.util.ContentType
- Direct Known Subclasses:
ContentType.SettableContentType
This class serves as a Content-Type holder, plus it implements useful utility methods to work with content-type.
- Author:
- Alexey Stashok
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]Composes a content-type array, based on the mime-type represented by a byte array and a charset attribute value, represented by aString.get()intUsed in conjunction withgetByteArray().byte[]static StringgetCharsetFromContentType(String contentType) Parse the character encoding from the specified content type header.Returns the mime-type part of the content-type (the part without charset attribute).booleanbooleanisSet()static ContentTypenewContentType(String contentType) Creates aContentTypewrapper over aStringcontent-type representation.static ContentTypenewContentType(String mimeType, String characterEncoding) Creates aContentTypewrapper over the passed mime-type and character encoding.prepare()Prepare the ContentType for the serialization.static byte[]removeCharset(byte[] contentType) Removes the charset attribute from the content-type represented by an array.protected voidreset()Resets the ContentType state.voidSerializes this ContentType value into a passedDataChunk.protected voidSets the content type.protected voidset(ContentType contentType) Sets the content type.protected voidsetCharacterEncoding(String charset) Sets the the character encoding (the content-type's charset attribute value).protected voidsetMimeType(String mimeType) Sets the mime-type part of the content-type (the part without charset attribute).toString()
-
Method Details
-
newSettableContentType
- Returns:
ContentType.SettableContentType, the mutableContentTyperepresentation.
-
newContentType
Creates aContentTypewrapper over aStringcontent-type representation.- Parameters:
contentType-Stringcontent-type representation- Returns:
- a
ContentTypewrapper over aStringcontent-type representation
-
newContentType
Creates aContentTypewrapper over the passed mime-type and character encoding.- Parameters:
mimeType-StringmimeType-type representation (like "text/plain", "text/html", etc), which doesn't contain charset informationcharacterEncoding- charset attribute to be used with the mime-type- Returns:
- a
ContentTypewrapper over the passed mime-type and character encoding
-
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:
- this ContentType
-
isSet
public boolean isSet()- Returns:
- true if either mime-type or character encoding is set, or false otherwise
-
isMimeTypeSet
public boolean isMimeTypeSet()- Returns:
- true if mime-type is set, or false otherwise
-
getMimeType
Returns the mime-type part of the content-type (the part without charset attribute).- Returns:
- the mime-type part of the content-type (the part without charset attribute)
-
setMimeType
Sets the mime-type part of the content-type (the part without charset attribute).- Parameters:
mimeType- the mime-type part of the content-type (the part without charset attribute)
-
getCharacterEncoding
- Returns:
- the character encoding (the content-type's charset attribute value)
-
setCharacterEncoding
Sets the the character encoding (the content-type's charset attribute value).- Parameters:
charset- the character encoding (the content-type's charset attribute value)
-
getArrayLen
public int getArrayLen()Used in conjunction withgetByteArray(). The array returned by the aforementioned method may be larger than the data contained therein. This method will return the proper data length.- Returns:
- the data length within the array returned by
getByteArray()
-
getByteArray
public byte[] getByteArray()- Returns:
- the byte array representation of the content-type
-
get
- Returns:
- the content type of this HTTP message.
-
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().- Parameters:
contentType- the content type
-
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.- Parameters:
contentType- the content type
-
serializeToDataChunk
Serializes this ContentType value into a passedDataChunk.- Parameters:
dc-DataChunk
-
reset
protected void reset()Resets the ContentType state. -
toString
-
getCharsetFromContentType
Parse the character encoding from the specified content type header. If the content type is null, or there is no explicit character encoding,nullis returned.- Parameters:
contentType- a content type header- Returns:
- the contentType's charset attribute value
-
removeCharset
public static byte[] removeCharset(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- the content-type represented by an array- Returns:
- a new array, which represents the same content-type as a given one, but without charset attribute
-
compose
Composes a content-type array, based on the mime-type represented by a byte array and a charset attribute value, represented by aString.- Parameters:
mimeType- a mime-type part of the content-type (doesn't contain charset attribute)charset- charset attribute value- Returns:
- a content-type array, composed of the mime-type represented by a byte array and a charset attribute value,
represented by a
String
-