public final class RawFrame extends Object
The structure of a frame is described in RFC6455, section 5.2. Base Framing Protocol.
Modifier and Type | Field and Description |
---|---|
static byte |
OPCODE_BINARY_FRAME
Opcode to denote a binary frame.
|
static byte |
OPCODE_CONNECTION_CLOSE
Opcode to denote a connection close.
|
static byte |
OPCODE_CONTINUATION_FRAME
Opcode to denote a continuation frame.
|
static byte |
OPCODE_PING
Opcode to denote a ping.
|
static byte |
OPCODE_PONG
Opcode to denote a pong.
|
static byte |
OPCODE_TEXT_FRAME
Opcode to denote a text frame.
|
Constructor and Description |
---|
RawFrame(byte[] bytes)
bytes will be copied internally so that it is not tied to the newly created instance and can then be
reused. |
Modifier and Type | Method and Description |
---|---|
void |
append(RawFrame f)
Appends the payload of a frame into the current frame.
|
byte[] |
getBytes()
Note: this is not a copy of the internal representation.
|
long |
getExtendedLength()
Get the extended length of the frame.
|
byte |
getFIN()
FIN is a bit.
|
byte |
getLength()
A frame has a field called payload length.
|
byte |
getMASK()
MASK is a bit.
|
byte[] |
getMaskingKey()
Masking key is an optional field of the websocket protocol.
|
byte |
getOpcode()
Opcode is 4 bits.
|
byte[] |
getPayload(boolean unmaskIfNeeded)
The payload (= 'real' data) of this frame.
|
String |
getPayloadAsString(boolean unmaskIfNeeded) |
long |
getPayloadLength()
Gets the payload length.
|
byte |
getRSV()
RSV are 3 bits.
|
boolean |
hasExtendedLength()
Tell whether this frame has an extended length field.
|
boolean |
hasValidOpcode()
Test the opcode of this frame against possible opcodes provided by RFC6455.
|
boolean |
hasVeryExtendedLength()
Tell whether this frame has an extended length field.
|
boolean |
isControlFrame()
Tell whether this frame is a control frame or not.
|
boolean |
isMasked()
A convenient method to test whether the frame is masked or not.
|
boolean |
isValid()
Tell whether is valid or not, according to the RFC6455.
|
void |
setLength(long length) |
public static final byte OPCODE_BINARY_FRAME
public static final byte OPCODE_CONNECTION_CLOSE
public static final byte OPCODE_CONTINUATION_FRAME
public static final byte OPCODE_PING
public static final byte OPCODE_PONG
public static final byte OPCODE_TEXT_FRAME
public RawFrame(byte[] bytes) throws IllegalArgumentException
bytes
will be copied internally so that it is not tied to the newly created instance and can then be
reused.bytes
- the data used to create the frameIllegalArgumentException
- if bytes
is nullpublic void append(RawFrame f)
f
- the frame to gets the payload from.public byte[] getBytes()
public long getExtendedLength()
public byte getFIN()
public byte getLength()
public byte getMASK()
public byte[] getMaskingKey()
public byte getOpcode()
public byte[] getPayload(boolean unmaskIfNeeded)
unmaskIfNeeded
- if 'true' and MASK is 1 then it returns the unmasked payload; otherwise, the payload is returned
directlypublic String getPayloadAsString(boolean unmaskIfNeeded)
public long getPayloadLength()
public byte getRSV()
public boolean hasExtendedLength()
public boolean hasValidOpcode()
public boolean hasVeryExtendedLength()
public boolean isControlFrame()
public boolean isMasked()
public boolean isValid() throws IOException
IOException
- if the frame does not respect the RFC6455UnsupportedEncodingException
- if the frame does not validate the UTF8 formatpublic void setLength(long length)