public interface WebSocketMessage extends ByteSource
A WebSocket message contains a sequence of bytes.
Note that WebSocketMessage
is a subtype of ByteSource
.
A WebSocket message is either Text or Binary, identified by the message header. A Text message contains texts encoded in UTF-8 bytes. A Binary message can contain arbitrary bytes.
See ByteSource
methods for reading bytes/chars from the message.
See static methods in this interface for creating messages,
e.g. text(CharSequence)
, binary(byte[])
.
Abstract Method | |
---|---|
boolean |
isText()
Whether this is a Text message.
|
Static Methods | |
WebSocketMessage |
text(CharSequence chars)
Create a text message containing the chars.
|
WebSocketMessage |
text(ByteSource byteSource)
Wrap a ByteSource as a text message.
|
WebSocketMessage |
binary(byte[] bytes)
Create a binary message containing the bytes.
|
WebSocketMessage |
binary(ByteSource byteSource)
Wrap a ByteSource as a binary message.
|
boolean isText()
static WebSocketMessage text(CharSequence chars)
static WebSocketMessage text(ByteSource byteSource)
The bytes in `byteSource` must form a valid UTF-8 byte sequence.
static WebSocketMessage binary(byte[] bytes)
static WebSocketMessage binary(ByteSource byteSource)