Class ContentType
java.lang.Object
cloud.opencode.base.web.http.ContentType
Content Type - HTTP Content-Type Header Values
内容类型 - HTTP Content-Type 头部值
This class provides common MIME types and utilities for Content-Type handling.
此类提供常见的 MIME 类型和 Content-Type 处理工具。
Example | 示例:
String json = ContentType.APPLICATION_JSON;
ContentType type = ContentType.parse("text/html; charset=utf-8");
String mimeType = type.getMimeType();
Charset charset = type.getCharset();
Features | 主要功能:
- Common MIME type constants - 常见MIME类型常量
- Content-Type header parsing - Content-Type头部解析
- Charset and boundary support - 字符集和边界支持
- Type checking methods (isJson, isXml, etc.) - 类型检查方法
Usage Examples | 使用示例:
ContentType json = ContentType.json();
ContentType parsed = ContentType.parse("text/html; charset=utf-8");
boolean isJson = parsed.isJson();
Security | 安全性:
- Thread-safe: Yes (immutable) - 是(不可变)
- Null-safe: Partial (parse returns null for null input) - 部分(parse对null输入返回null)
- Since:
- JDK 25, opencode-base-web V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Method Summary
Modifier and TypeMethodDescriptionstatic ContentTypebinary()Creates a ContentType for binary data.static ContentTypeform()Creates a ContentType for form data.Gets the boundary for multipart.Gets the charset.getCharsetOrDefault(Charset defaultCharset) Gets the charset or default.Gets the MIME type.booleanisForm()Checks if this is a form type.booleanisJson()Checks if this is a JSON type.booleanChecks if this is a multipart type.booleanisText()Checks if this is a text type.booleanisXml()Checks if this is an XML type.static ContentTypejson()Creates a ContentType for JSON with UTF-8.static ContentTypeCreates a ContentType for multipart with boundary.static ContentTypeCreates a ContentType with MIME type only.static ContentTypeCreates a ContentType with MIME type and charset.static ContentTypeParses a Content-Type header value.static ContentTypetext()Creates a ContentType for plain text with UTF-8.toString()Returns the Content-Type header value.static ContentTypexml()Creates a ContentType for XML with UTF-8.
-
Field Details
-
APPLICATION_JSON
- See Also:
-
APPLICATION_XML
- See Also:
-
APPLICATION_FORM_URLENCODED
- See Also:
-
APPLICATION_OCTET_STREAM
- See Also:
-
APPLICATION_PDF
- See Also:
-
APPLICATION_ZIP
- See Also:
-
TEXT_PLAIN
- See Also:
-
TEXT_HTML
- See Also:
-
TEXT_XML
- See Also:
-
TEXT_CSS
- See Also:
-
TEXT_JAVASCRIPT
- See Also:
-
MULTIPART_FORM_DATA
- See Also:
-
MULTIPART_MIXED
- See Also:
-
IMAGE_PNG
- See Also:
-
IMAGE_JPEG
- See Also:
-
IMAGE_GIF
- See Also:
-
IMAGE_SVG
- See Also:
-
IMAGE_WEBP
- See Also:
-
AUDIO_MPEG
- See Also:
-
VIDEO_MP4
- See Also:
-
-
Method Details
-
of
Creates a ContentType with MIME type only. 仅使用 MIME 类型创建 ContentType。- Parameters:
mimeType- the MIME type - MIME 类型- Returns:
- the ContentType - ContentType
-
of
Creates a ContentType with MIME type and charset. 使用 MIME 类型和字符集创建 ContentType。- Parameters:
mimeType- the MIME type - MIME 类型charset- the charset - 字符集- Returns:
- the ContentType - ContentType
-
json
Creates a ContentType for JSON with UTF-8. 创建 UTF-8 编码的 JSON ContentType。- Returns:
- the ContentType - ContentType
-
xml
Creates a ContentType for XML with UTF-8. 创建 UTF-8 编码的 XML ContentType。- Returns:
- the ContentType - ContentType
-
form
Creates a ContentType for form data. 创建表单数据的 ContentType。- Returns:
- the ContentType - ContentType
-
multipart
Creates a ContentType for multipart with boundary. 使用边界创建 multipart 的 ContentType。- Parameters:
boundary- the boundary - 边界- Returns:
- the ContentType - ContentType
-
text
Creates a ContentType for plain text with UTF-8. 创建 UTF-8 编码的纯文本 ContentType。- Returns:
- the ContentType - ContentType
-
binary
Creates a ContentType for binary data. 创建二进制数据的 ContentType。- Returns:
- the ContentType - ContentType
-
parse
Parses a Content-Type header value. 解析 Content-Type 头部值。- Parameters:
value- the header value - 头部值- Returns:
- the ContentType - ContentType
-
getMimeType
-
getCharset
-
getCharsetOrDefault
-
getBoundary
Gets the boundary for multipart. 获取 multipart 的边界。- Returns:
- the boundary or null - 边界或 null
-
isJson
public boolean isJson()Checks if this is a JSON type. 检查是否是 JSON 类型。- Returns:
- true if JSON - 如果是 JSON 返回 true
-
isXml
public boolean isXml()Checks if this is an XML type. 检查是否是 XML 类型。- Returns:
- true if XML - 如果是 XML 返回 true
-
isText
public boolean isText()Checks if this is a text type. 检查是否是文本类型。- Returns:
- true if text - 如果是文本返回 true
-
isMultipart
public boolean isMultipart()Checks if this is a multipart type. 检查是否是 multipart 类型。- Returns:
- true if multipart - 如果是 multipart 返回 true
-
isForm
public boolean isForm()Checks if this is a form type. 检查是否是表单类型。- Returns:
- true if form - 如果是表单返回 true
-
toString
-