public class WebSocketFrame extends Object
WebSocket frame.
href="https://tools.ietf.org/html/rfc6455#section-5"
>RFC 6455, 5. Data Framing</a>| 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()
Get the value of FIN bit.
public WebSocketFrame setFin(boolean fin)
Set the value of FIN bit.
fin - The value of FIN bit.this object.public boolean getRsv1()
Get the value of RSV1 bit.
public WebSocketFrame setRsv1(boolean rsv1)
Set the value of RSV1 bit.
rsv1 - The value of RSV1 bit.this object.public boolean getRsv2()
Get the value of RSV2 bit.
public WebSocketFrame setRsv2(boolean rsv2)
Set the value of RSV2 bit.
rsv2 - The value of RSV2 bit.this object.public boolean getRsv3()
Get the value of RSV3 bit.
public WebSocketFrame setRsv3(boolean rsv3)
Set the value of RSV3 bit.
rsv3 - The value of RSV3 bit.this object.public int getOpcode()
Get the opcode.
<table border="1" cellpadding="5" style="table-collapse: collapse;"> <caption>WebSocket opcode</caption> <thead> <tr> <th>Value</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>0x0</td> <td>Frame continuation</td> </tr> <tr> <td>0x1</td> <td>Text frame</td> </tr> <tr> <td>0x2</td> <td>Binary frame</td> </tr> <tr> <td>0x3-0x7</td> <td>Reserved</td> </tr> <tr> <td>0x8</td> <td>Connection close</td> </tr> <tr> <td>0x9</td> <td>Ping</td> </tr> <tr> <td>0xA</td> <td>Pong</td> </tr> <tr> <td>0xB-0xF</td> <td>Reserved</td> </tr> </tbody> </table>
WebSocketOpcodepublic WebSocketFrame setOpcode(int opcode)
Set the opcode
opcode - The opcode.this object.WebSocketOpcodepublic boolean isContinuationFrame()
Check if this frame is a continuation frame.
<p>
This method returns true when the value of the
opcode is 0x0 (WebSocketOpcode.CONTINUATION).
</p>
true if this frame is a continuation frame
(= if the opcode is 0x0).public boolean isTextFrame()
Check if this frame is a text frame.
<p>
This method returns true when the value of the
opcode is 0x1 (WebSocketOpcode.TEXT).
</p>
true if this frame is a text frame
(= if the opcode is 0x1).public boolean isBinaryFrame()
Check if this frame is a binary frame.
<p>
This method returns true when the value of the
opcode is 0x2 (WebSocketOpcode.BINARY).
</p>
true if this frame is a binary frame
(= if the opcode is 0x2).public boolean isCloseFrame()
Check if this frame is a close frame.
<p>
This method returns true when the value of the
opcode is 0x8 (WebSocketOpcode.CLOSE).
</p>
true if this frame is a close frame
(= if the opcode is 0x8).public boolean isPingFrame()
Check if this frame is a ping frame.
<p>
This method returns true when the value of the
opcode is 0x9 (WebSocketOpcode.PING).
</p>
true if this frame is a ping frame
(= if the opcode is 0x9).public boolean isPongFrame()
Check if this frame is a pong frame.
<p>
This method returns true when the value of the
opcode is 0xA (WebSocketOpcode.PONG).
</p>
true if this frame is a pong frame
(= if the opcode is 0xA).public boolean isDataFrame()
Check if this frame is a data frame.
<p>
This method returns true when the value of the
opcode is in between 0x1 and 0x7.
</p>
true if this frame is a data frame
(= if the opcode is in between 0x1 and 0x7).public boolean isControlFrame()
Check if this frame is a control frame.
<p>
This method returns true when the value of the
opcode is in between 0x8 and 0xF.
</p>
true if this frame is a control frame
(= if the opcode is in between 0x8 and 0xF).public boolean hasPayload()
Check if this frame has payload.
true if this frame has payload.public int getPayloadLength()
Get the payload length.
public byte[] getPayload()
Get the unmasked payload.
null may be returned.public String getPayloadText()
Get the unmasked payload as a text.
public WebSocketFrame setPayload(byte[] payload)
Set the unmasked payload.
<p> Note that the payload length of a <a href="http://tools.ietf.org/html/rfc6455#section-5.5" >control frame</a> must be 125 bytes or less. </p>
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)
Set the payload. The given string is converted to a byte array in UTF-8 encoding.
<p> Note that the payload length of a <a href="http://tools.ietf.org/html/rfc6455#section-5.5" >control frame</a> must be 125 bytes or less. </p>
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)
Set the payload that conforms to the payload format of close frames.
<p> The given parameters are encoded based on the rules described in "<a href="http://tools.ietf.org/html/rfc6455#section-5.5.1" >5.5.1. Close</a>" of RFC 6455. </p>
<p> Note that the reason should not be too long because the payload length of a <a href="http://tools.ietf.org/html/rfc6455#section-5.5" >control frame</a> must be 125 bytes or less. </p>
closeCode - The close code.reason - The reason. null is accepted. An empty string
is treated in the same way as null.this object.href="http://tools.ietf.org/html/rfc6455#section-5.5.1"
>RFC 6455, 5.5.1. Close</a>,
WebSocketCloseCodepublic int getCloseCode()
Parse the first two bytes of the payload as a close code.
<p>
If any payload is not set or the length of the payload is less than 2,
this method returns 1005 (WebSocketCloseCode.NONE).
</p>
<p> The value returned from this method is meaningless if this frame is not a close frame. </p>
href="http://tools.ietf.org/html/rfc6455#section-5.5.1"
>RFC 6455, 5.5.1. Close</a>,
WebSocketCloseCodepublic String getCloseReason()
Parse the third and subsequent bytes of the payload as a close reason.
<p>
If any payload is not set or the length of the payload is less than 3,
this method returns null.
</p>
<p> The value returned from this method is meaningless if this frame is not a close frame. </p>
public static WebSocketFrame createContinuationFrame()
Create a continuation frame. Note that the FIN bit of the returned frame is false.
CONTINUATION and
payload is null.public static WebSocketFrame createContinuationFrame(byte[] payload)
Create a continuation frame. Note that the FIN bit of the returned frame is false.
payload - The payload for a newly create frame.CONTINUATION and
payload is the given one.public static WebSocketFrame createContinuationFrame(String payload)
Create a continuation frame. Note that the FIN bit of the returned frame is false.
payload - The payload for a newly create frame.CONTINUATION and
payload is the given one.public static WebSocketFrame createTextFrame(String payload)
Create a text frame.
payload - The payload for a newly created frame.TEXT and payload is
the given one.public static WebSocketFrame createBinaryFrame(byte[] payload)
Create a binary frame.
payload - The payload for a newly created frame.BINARY and payload is
the given one.public static WebSocketFrame createCloseFrame()
Create a close frame.
CLOSE and payload is
null.public static WebSocketFrame createCloseFrame(int closeCode)
Create a close frame.
closeCode - The close code.CLOSE and payload
contains a close code.WebSocketCloseCodepublic static WebSocketFrame createCloseFrame(int closeCode, String reason)
Create a close frame.
closeCode - The close code.reason - The close reason.
Note that a control frame’s payload length must be 125 bytes or less
(RFC 6455, <a href="https://tools.ietf.org/html/rfc6455#section-5.5"
>5.5. Control Frames</a>).CLOSE and payload
contains a close code and a close reason.WebSocketCloseCodepublic static WebSocketFrame createPingFrame()
Create a ping frame.
PING and payload is
null.public static WebSocketFrame createPingFrame(byte[] payload)
Create a ping frame.
payload - The payload for a newly created frame.
Note that a control frame’s payload length must be 125 bytes or less
(RFC 6455, <a href="https://tools.ietf.org/html/rfc6455#section-5.5"
>5.5. Control Frames</a>).PING and payload is
the given one.public static WebSocketFrame createPingFrame(String payload)
Create a ping frame.
payload - The payload for a newly created frame.
Note that a control frame’s payload length must be 125 bytes or less
(RFC 6455, <a href="https://tools.ietf.org/html/rfc6455#section-5.5"
>5.5. Control Frames</a>).PING and payload is
the given one.public static WebSocketFrame createPongFrame()
Create a pong frame.
PONG and payload is
null.public static WebSocketFrame createPongFrame(byte[] payload)
Create a pong frame.
payload - The payload for a newly created frame.
Note that a control frame’s payload length must be 125 bytes or less
(RFC 6455, <a href="https://tools.ietf.org/html/rfc6455#section-5.5"
>5.5. Control Frames</a>).PONG and payload is
the given one.public static WebSocketFrame createPongFrame(String payload)
Create a pong frame.
payload - The payload for a newly created frame.
Note that a control frame’s payload length must be 125 bytes or less
(RFC 6455, <a href="https://tools.ietf.org/html/rfc6455#section-5.5"
>5.5. Control Frames</a>).PONG and payload is
the given one.Copyright © 2021. All Rights Reserved.