public enum MessageType extends Enum<MessageType>
文件名:ResponseContentType.java
用途: 定义接口响应内容的格式枚举
编码时间:2022年4月12日 上午8:57:02
修改时间:2022年8月8日 下午4:10:29
Enum Constant and Description |
---|
BINARY
二进制编码类型
|
FILE
文件类型
|
FORM_DATA
表单类型
|
HTML
html类型
|
JSON
json类型
|
NONE
无报文类型
|
RAW
纯文本类型
|
X_WWW_FORM_URLENCODED
表单上传编码类型
|
XML
xml类型
|
Modifier and Type | Method and Description |
---|---|
String |
getMediaValue()
该方法用于返回报文类型名称
|
MessageType |
setCharset(String charset)
该方法用于设置报文类型的编码格式
|
String |
toMessageTypeString()
该方法用于返回报文类型的详细文本内容(包含编码)
|
static MessageType |
typeOf(String typeName)
该方法用于比对消息类型名称,返回对应的消息类型枚举
|
static MessageType |
typeText2Type(String type)
该方法用于将枚举文本转换为消息枚举
|
static MessageType |
typeText2Type(String type,
Function<String,String> mapper)
该方法用于将枚举文本转换为消息枚举
|
static MessageType |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static MessageType[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final MessageType JSON
public static final MessageType XML
public static final MessageType HTML
public static final MessageType RAW
public static final MessageType FORM_DATA
public static final MessageType X_WWW_FORM_URLENCODED
public static final MessageType BINARY
public static final MessageType FILE
public static final MessageType NONE
public static MessageType[] values()
for (MessageType c : MessageType.values()) System.out.println(c);
public static MessageType valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic String getMediaValue()
public static MessageType typeOf(String typeName)
typeName
- 消息类型名称public MessageType setCharset(String charset)
charset
- 编码格式名称字符串public String toMessageTypeString()
public static MessageType typeText2Type(String type)
该方法本质上与valueOf(String)
方法的作用一致,但其中加上了对文本的内容的判空、对文本内容大写转换、
对特殊文本进行处理以及对异常文本进行汉化的操作。可转换的枚举文本如下:
type
- 枚举文本内容IllegalArgumentException
- 当枚举文本为空或不能转换成枚举时抛出的异常public static MessageType typeText2Type(String type, Function<String,String> mapper)
该方法与typeText2Type(String)
方法类似,其可对传入的文本进行自定义的转换,例如欲将传入的"text"转换为"raw",则可写为
MessageType.typeText2MessageType("text", type -> {
if ("text".equals(text)) {
text = "raw";
}
return text;
});
type
- 枚举文本内容mapper
- 枚举文本的处理方法IllegalArgumentException
- 当枚举文本为空或不能转换成枚举时抛出的异常Copyright © 2024. All rights reserved.