Class MimeTypes
java.lang.Object
org.eclipse.jetty.http.MimeTypes
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static enum
Enumeration of predefined MimeTypes. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetAssumedCharset
(String contentType) getAssumedCharsetName
(String contentType) static String
Get the base value, stripped of any parametersstatic MimeTypes.Type
getBaseType
(String contentType) Get the base type of this type, which is the type without a charset specifiedgetCharset
(String mimeType) Get the explicit, assumed, or inferred Charset for a mime typegetCharset
(HttpField field) Get the explicit, assumed, or inferred Charset for a HttpField containing a mime type valuestatic String
getCharsetFromContentType
(String value) Efficiently extract the charset value from aContent-Type
stringstatic Charset
Efficiently extract the charset value from aContent-Type
HttpField
.static String
Efficiently extract the base mime-type from a content-type valuegetInferredCharset
(String contentType) getInferredCharsetName
(String contentType) static Charset
getKnownCharset
(String charsetName) getMimeByExtension
(String filename) Get the MIME type by filename extension.getMimeForExtension
(String extension) static String
static MimeTypes.Type
boolean
isCharsetAssumed
(String contentType) static boolean
isKnownLocale
(Locale locale) protected void
loadEncodings
(InputStream stream, String resourceName) protected void
loadMimeProperties
(InputStream stream, String resourceName) static String
normalizeCharset
(String charsetName) Convert alternate charset names (eg utf8) to normalized name (eg UTF-8).static String
normalizeCharset
(String charsetName, int offset, int length) Convert alternate charset names (eg utf8) to normalized name (eg UTF-8).
-
Field Details
-
ISO_8859_1
-
UTF8
-
UTF16
-
CACHE
-
_mimeMap
-
_inferredEncodings
-
_assumedEncodings
-
_assumedNoEncodings
-
DEFAULTS
-
-
Constructor Details
-
MimeTypes
public MimeTypes() -
MimeTypes
-
-
Method Details
-
getBase
-
getBaseType
Get the base type of this type, which is the type without a charset specified- Parameters:
contentType
- The mimetype as a string- Returns:
- The base type or this type if it is a base type
-
isKnownLocale
-
normalizeCharset
-
normalizeCharset
Convert alternate charset names (eg utf8) to normalized name (eg UTF-8).- Parameters:
charsetName
- the charset to normalizeoffset
- the offset in the charsetlength
- the length of the charset in the input param- Returns:
- the normalized charset (or null if not found)
-
getKnownCharset
- Parameters:
charsetName
- The name of the charset- Returns:
- The
Charset
for the normalized name - Throws:
UnsupportedEncodingException
- Thrown if the charset is not known to the JVM.
-
loadMimeProperties
- Throws:
IOException
-
loadEncodings
- Throws:
IOException
-
getCharset
public Charset getCharset(HttpField field) throws IllegalCharsetNameException, UnsupportedCharsetException Get the explicit, assumed, or inferred Charset for a HttpField containing a mime type value- Parameters:
field
- HttpField with a mime type value (e.g. Content-Type)- Returns:
- A
Charset
or null; - Throws:
IllegalCharsetNameException
- If the given charset name is illegalUnsupportedCharsetException
- If no support for the named charset is available in this instance of the Java virtual machine
-
getCharset
public Charset getCharset(String mimeType) throws IllegalCharsetNameException, UnsupportedCharsetException Get the explicit, assumed, or inferred Charset for a mime type- Parameters:
mimeType
- String form or a mimeType- Returns:
- A
Charset
or null; - Throws:
IllegalCharsetNameException
- If the given charset name is illegalUnsupportedCharsetException
- If no support for the named charset is available in this instance of the Java virtual machine
-
getMimeByExtension
-
getMimeForExtension
-
getInferredCharset
- Parameters:
contentType
- The content type to obtain a charset for.- Returns:
- A Charset is returned if it can be inferred from content-type. This is essentially a default charset determined for the contentType. For example, the content-type "text/html" may be configured to have an inferred charset of "utf-8", in which case setting that content-type should result in a value of "text/html;charset=utf8".
- See Also:
-
getAssumedCharset
- Parameters:
contentType
- The content type to obtain a charset for.- Returns:
- A Charset is returned if it can be assumed from content-type. This is essentially a known charset
for the specific contentType. For example, the content-type "application/json" is specified to use utf-8,
so it has an assumed charset of "utf-8". As this is universally known, there is no need to modify the
the content-type which will just have a value of "application/json". Note that some content-types may be
assumed to have no charset, in which case
isCharsetAssumed(String)
must be used. - See Also:
-
isCharsetAssumed
- Parameters:
contentType
- The content-type to obtain a charset for- Returns:
True
if the content-type is assumed to have a specific charset (include assumed to have no charset. For example "application/json" is assumed as it has a specified charset of "utf-8". Another example is "image/jpeg", which is assumed to have no charset, so it would also return true.
-
getInferredCharsetName
- Parameters:
contentType
- The content type to obtain a charset for.- Returns:
- The string value of
getInferredCharset(String)
- See Also:
-
getAssumedCharsetName
- Parameters:
contentType
- The content type to obtain a charset for.- Returns:
- The string value of
getAssumedCharset(String)
; or the empty string if the type is assumed to not have a charset; ornull
of the type has no assumed charset. - See Also:
-
getMimeMap
-
getMimeTypeFromContentType
-
getMimeTypeAsStringFromContentType
-
getCharsetFromContentType
-
getCharsetFromContentType
-
getContentTypeWithoutCharset
-