类 WebSocketMessage
- java.lang.Object
- org.springframework.web.reactive.socket.WebSocketMessage
public class WebSocketMessage extends Object
Representation of a WebSocket message.See static factory methods in
WebSocketSessionfor creating messages with theDataBufferFactoryfor the session.- 从以下版本开始:
- 5.0
- 作者:
- Rossen Stoyanchev
嵌套类概要
嵌套类 修饰符和类型 类 说明 static classWebSocketMessage.TypeWebSocket message types.
构造器概要
构造器 构造器 说明 WebSocketMessage(WebSocketMessage.Type type, DataBuffer payload)Constructor for a WebSocketMessage.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 booleanequals(Object other)DataBuffergetPayload()Return the message payload.StringgetPayloadAsText()A variant ofgetPayloadAsText(Charset)that usesUTF-8for decoding the raw content to text.StringgetPayloadAsText(Charset charset)A shortcut for decoding the raw content of the message to text with the given character encoding.WebSocketMessage.TypegetType()Return the message type (text, binary, etc).inthashCode()voidrelease()Release the payloadDataBufferwhich is useful on runtimes (e.g.WebSocketMessageretain()Retain the data buffer for the message payload, which is useful on runtimes (e.g.StringtoString()
构造器详细资料
WebSocketMessage
public WebSocketMessage(WebSocketMessage.Type type, DataBuffer payload)
Constructor for a WebSocketMessage.See static factory methods in
WebSocketSessionor alternatively useWebSocketSession.bufferFactory()to create the payload and then invoke this constructor.
方法详细资料
getType
public WebSocketMessage.Type getType()
Return the message type (text, binary, etc).
getPayload
public DataBuffer getPayload()
Return the message payload.
getPayloadAsText
public String getPayloadAsText()
A variant ofgetPayloadAsText(Charset)that usesUTF-8for decoding the raw content to text.
getPayloadAsText
public String getPayloadAsText(Charset charset)
A shortcut for decoding the raw content of the message to text with the given character encoding. This is useful for text WebSocket messages, or otherwise when the payload is expected to contain text.- 参数:
charset- the character encoding- 从以下版本开始:
- 5.0.5
retain
public WebSocketMessage retain()
Retain the data buffer for the message payload, which is useful on runtimes (e.g. Netty) with pooled buffers. A shortcut for:DataBuffer payload = message.getPayload(); DataBufferUtils.retain(payload);
release
public void release()
Release the payloadDataBufferwhich is useful on runtimes (e.g. Netty) with pooled buffers such as Netty. A shortcut for:DataBuffer payload = message.getPayload(); DataBufferUtils.release(payload);