public class WebSocketFrame extends Object
Constructor and Description |
---|
WebSocketFrame() |
Modifier and Type | Method and Description |
---|---|
static WebSocketFrame |
createBinaryFrame(byte[] payload)
Create a binary frame.
|
static WebSocketFrame |
createCloseFrame()
Create a close frame.
|
static WebSocketFrame |
createCloseFrame(int closeCode)
Create a close frame.
|
static WebSocketFrame |
createCloseFrame(int closeCode,
String reason)
Create a close frame.
|
static WebSocketFrame |
createContinuationFrame()
Create a continuation frame.
|
static WebSocketFrame |
createContinuationFrame(byte[] payload)
Create a continuation frame.
|
static WebSocketFrame |
createContinuationFrame(String payload)
Create a continuation frame.
|
static WebSocketFrame |
createPingFrame()
Create a ping frame.
|
static WebSocketFrame |
createPingFrame(byte[] payload)
Create a ping frame.
|
static WebSocketFrame |
createPingFrame(String payload)
Create a ping frame.
|
static WebSocketFrame |
createPongFrame()
Create a pong frame.
|
static WebSocketFrame |
createPongFrame(byte[] payload)
Create a pong frame.
|
static WebSocketFrame |
createPongFrame(String payload)
Create a pong frame.
|
static WebSocketFrame |
createTextFrame(String payload)
Create a text frame.
|
int |
getCloseCode()
Parse the first two bytes of the payload as a close code.
|
String |
getCloseReason()
Parse the third and subsequent bytes of the payload as a close reason.
|
boolean |
getFin()
Get the value of FIN bit.
|
int |
getOpcode()
Get the opcode.
|
byte[] |
getPayload()
Get the unmasked payload.
|
int |
getPayloadLength()
Get the payload length.
|
String |
getPayloadText()
Get the unmasked payload as a text.
|
boolean |
getRsv1()
Get the value of RSV1 bit.
|
boolean |
getRsv2()
Get the value of RSV2 bit.
|
boolean |
getRsv3()
Get the value of RSV3 bit.
|
boolean |
hasPayload()
Check if this frame has payload.
|
boolean |
isBinaryFrame()
Check if this frame is a binary frame.
|
boolean |
isCloseFrame()
Check if this frame is a close frame.
|
boolean |
isContinuationFrame()
Check if this frame is a continuation frame.
|
boolean |
isControlFrame()
Check if this frame is a control frame.
|
boolean |
isDataFrame()
Check if this frame is a data frame.
|
boolean |
isPingFrame()
Check if this frame is a ping frame.
|
boolean |
isPongFrame()
Check if this frame is a pong frame.
|
boolean |
isTextFrame()
Check if this frame is a text frame.
|
WebSocketFrame |
setCloseFramePayload(int closeCode,
String reason)
Set the payload that conforms to the payload format of close frames.
|
WebSocketFrame |
setFin(boolean fin)
Set the value of FIN bit.
|
WebSocketFrame |
setOpcode(int opcode)
Set the opcode
|
WebSocketFrame |
setPayload(byte[] payload)
Set the unmasked payload.
|
WebSocketFrame |
setPayload(String payload)
Set the payload.
|
WebSocketFrame |
setRsv1(boolean rsv1)
Set the value of RSV1 bit.
|
WebSocketFrame |
setRsv2(boolean rsv2)
Set the value of RSV2 bit.
|
WebSocketFrame |
setRsv3(boolean rsv3)
Set the value of RSV3 bit.
|
String |
toString() |
public boolean getFin()
public WebSocketFrame setFin(boolean fin)
fin
- The value of FIN bit.this
object.public boolean getRsv1()
public WebSocketFrame setRsv1(boolean rsv1)
rsv1
- The value of RSV1 bit.this
object.public boolean getRsv2()
public WebSocketFrame setRsv2(boolean rsv2)
rsv2
- The value of RSV2 bit.this
object.public boolean getRsv3()
public WebSocketFrame setRsv3(boolean rsv3)
rsv3
- The value of RSV3 bit.this
object.public int getOpcode()
Value | Description |
---|---|
0x0 | Frame continuation |
0x1 | Text frame |
0x2 | Binary frame |
0x3-0x7 | Reserved |
0x8 | Connection close |
0x9 | Ping |
0xA | Pong |
0xB-0xF | Reserved |
WebSocketOpcode
public WebSocketFrame setOpcode(int opcode)
opcode
- The opcode.this
object.WebSocketOpcode
public boolean isContinuationFrame()
This method returns true
when the value of the
opcode is 0x0 (WebSocketOpcode.CONTINUATION
).
true
if this frame is a continuation frame
(= if the opcode is 0x0).public boolean isTextFrame()
This method returns true
when the value of the
opcode is 0x1 (WebSocketOpcode.TEXT
).
true
if this frame is a text frame
(= if the opcode is 0x1).public boolean isBinaryFrame()
This method returns true
when the value of the
opcode is 0x2 (WebSocketOpcode.BINARY
).
true
if this frame is a binary frame
(= if the opcode is 0x2).public boolean isCloseFrame()
This method returns true
when the value of the
opcode is 0x8 (WebSocketOpcode.CLOSE
).
true
if this frame is a close frame
(= if the opcode is 0x8).public boolean isPingFrame()
This method returns true
when the value of the
opcode is 0x9 (WebSocketOpcode.PING
).
true
if this frame is a ping frame
(= if the opcode is 0x9).public boolean isPongFrame()
This method returns true
when the value of the
opcode is 0xA (WebSocketOpcode.PONG
).
true
if this frame is a pong frame
(= if the opcode is 0xA).public boolean isDataFrame()
This method returns true
when the value of the
opcode is in between 0x1 and 0x7.
true
if this frame is a data frame
(= if the opcode is in between 0x1 and 0x7).public boolean isControlFrame()
This method returns true
when the value of the
opcode is in between 0x8 and 0xF.
true
if this frame is a control frame
(= if the opcode is in between 0x8 and 0xF).public boolean hasPayload()
true
if this frame has payload.public int getPayloadLength()
public byte[] getPayload()
null
may be returned.public String getPayloadText()
public WebSocketFrame setPayload(byte[] payload)
Note that the payload length of a control frame must be 125 bytes or less.
payload
- The unmasked payload. null
is accepted.
An empty byte array is treated in the same way
as null
.this
object.public WebSocketFrame setPayload(String payload)
Note that the payload length of a control frame must be 125 bytes or less.
payload
- The unmasked payload. null
is accepted.
An empty string is treated in the same way as
null
.this
object.public WebSocketFrame setCloseFramePayload(int closeCode, String reason)
The given parameters are encoded based on the rules described in "5.5.1. Close" of RFC 6455.
Note that the reason should not be too long because the payload length of a control frame must be 125 bytes or less.
closeCode
- The close code.reason
- The reason. null
is accepted. An empty string
is treated in the same way as null
.this
object.WebSocketCloseCode
public int getCloseCode()
If any payload is not set or the length of the payload is less than 2,
this method returns 1005 (WebSocketCloseCode.NONE
).
The value returned from this method is meaningless if this frame is not a close frame.
WebSocketCloseCode
public String getCloseReason()
If any payload is not set or the length of the payload is less than 3,
this method returns null
.
The value returned from this method is meaningless if this frame is not a close frame.
public static WebSocketFrame createContinuationFrame()
CONTINUATION
and
payload is null
.public static WebSocketFrame createContinuationFrame(byte[] payload)
payload
- The payload for a newly create frame.CONTINUATION
and
payload is the given one.public static WebSocketFrame createContinuationFrame(String payload)
payload
- The payload for a newly create frame.CONTINUATION
and
payload is the given one.public static WebSocketFrame createTextFrame(String payload)
payload
- The payload for a newly created frame.TEXT
and payload is
the given one.public static WebSocketFrame createBinaryFrame(byte[] payload)
payload
- The payload for a newly created frame.BINARY
and payload is
the given one.public static WebSocketFrame createCloseFrame()
CLOSE
and payload is
null
.public static WebSocketFrame createCloseFrame(int closeCode)
closeCode
- The close code.CLOSE
and payload
contains a close code.WebSocketCloseCode
public static WebSocketFrame createCloseFrame(int closeCode, String reason)
closeCode
- The close code.reason
- The close reason.
Note that a control frame's payload length must be 125 bytes or less
(RFC 6455, 5.5. Control Frames).CLOSE
and payload
contains a close code and a close reason.WebSocketCloseCode
public static WebSocketFrame createPingFrame()
PING
and payload is
null
.public static WebSocketFrame createPingFrame(byte[] payload)
payload
- The payload for a newly created frame.
Note that a control frame's payload length must be 125 bytes or less
(RFC 6455, 5.5. Control Frames).PING
and payload is
the given one.public static WebSocketFrame createPingFrame(String payload)
payload
- The payload for a newly created frame.
Note that a control frame's payload length must be 125 bytes or less
(RFC 6455, 5.5. Control Frames).PING
and payload is
the given one.public static WebSocketFrame createPongFrame()
PONG
and payload is
null
.public static WebSocketFrame createPongFrame(byte[] payload)
payload
- The payload for a newly created frame.
Note that a control frame's payload length must be 125 bytes or less
(RFC 6455, 5.5. Control Frames).PONG
and payload is
the given one.public static WebSocketFrame createPongFrame(String payload)
payload
- The payload for a newly created frame.
Note that a control frame's payload length must be 125 bytes or less
(RFC 6455, 5.5. Control Frames).PONG
and payload is
the given one.Copyright © 2021. All rights reserved.