public class WebSocketFrame extends Object implements Frame
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-------+-+-------------+-------------------------------+ |F|R|R|R| opcode|M| Payload len | Extended payload length | |I|S|S|S| (4) |A| (7) | (16/64) | |N|V|V|V| |S| | (if payload len==126/127) | | |1|2|3| |K| | | +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - + | Extended payload length continued, if payload len == 127 | + - - - - - - - - - - - - - - - +-------------------------------+ | |Masking-key, if MASK set to 1 | +-------------------------------+-------------------------------+ | Masking-key (continued) | Payload Data | +-------------------------------- - - - - - - - - - - - - - - - + : Payload Data continued ... : + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | Payload Data continued ... | +---------------------------------------------------------------+
Frame.Type
Modifier and Type | Field and Description |
---|---|
static int |
MAX_CONTROL_PAYLOAD
Maximum size of Control frame, per RFC 6455
|
protected byte |
opcode |
Constructor and Description |
---|
WebSocketFrame()
Default constructor
|
WebSocketFrame(byte opcode)
Construct form opcode
|
WebSocketFrame(Frame frame)
Copy constructor for the websocket frame.
|
WebSocketFrame(WebSocketFrame copy)
Copy constructor for the websocket frame.
|
WebSocketFrame(WebSocketFrame copy,
ByteBuffer altPayload)
Copy constructor for the websocket frame, with an alternate payload.
|
Modifier and Type | Method and Description |
---|---|
void |
assertValid() |
static WebSocketFrame |
binary() |
static WebSocketFrame |
binary(byte[] buf) |
boolean |
equals(Object obj) |
int |
getContinuationIndex()
The number of fragments this frame consists of.
|
byte[] |
getMask() |
byte |
getOpCode() |
ByteBuffer |
getPayload()
Get the payload ByteBuffer.
|
String |
getPayloadAsUTF8() |
int |
getPayloadLength() |
int |
getPayloadStart() |
Frame.Type |
getType() |
int |
hashCode() |
boolean |
hasPayload() |
boolean |
isContinuation() |
boolean |
isControlFrame() |
boolean |
isDataFrame() |
boolean |
isFin() |
boolean |
isLast()
Same as
Frame.isFin() |
boolean |
isLastFrame() |
boolean |
isMasked() |
boolean |
isRsv1() |
boolean |
isRsv2() |
boolean |
isRsv3() |
static WebSocketFrame |
ping() |
static WebSocketFrame |
pong() |
int |
position()
Get the position currently within the payload data.
|
int |
remaining()
Get the number of bytes remaining to write out to the Network ByteBuffer.
|
void |
reset() |
Frame |
setContinuation(boolean continuation) |
Frame |
setContinuationIndex(int continuationIndex) |
WebSocketFrame |
setFin(boolean fin) |
Frame |
setMask(byte[] maskingKey) |
Frame |
setMasked(boolean mask) |
WebSocketFrame |
setOpCode(byte op) |
WebSocketFrame |
setPayload(byte[] buf)
Set the data and payload length.
|
WebSocketFrame |
setPayload(byte[] buf,
int offset,
int len)
Set the data and payload length.
|
WebSocketFrame |
setPayload(ByteBuffer buf)
Set the data payload.
|
WebSocketFrame |
setPayload(String str) |
WebSocketFrame |
setRsv1(boolean rsv1) |
WebSocketFrame |
setRsv2(boolean rsv2) |
WebSocketFrame |
setRsv3(boolean rsv3) |
static WebSocketFrame |
text() |
static WebSocketFrame |
text(String msg) |
String |
toString() |
public static final int MAX_CONTROL_PAYLOAD
protected byte opcode
public WebSocketFrame()
public WebSocketFrame(byte opcode)
public WebSocketFrame(Frame frame)
copy
- the websocket to copy.public WebSocketFrame(WebSocketFrame copy)
Note: the underlying payload is merely a ByteBuffer.slice()
of the input frame.
copy
- the websocket to copy.public WebSocketFrame(WebSocketFrame copy, ByteBuffer altPayload)
This is especially useful for Extensions to utilize when mutating the payload.
copy
- the websocket to copy.altPayload
- the alternate payload to use for this frame.public static WebSocketFrame binary()
public static WebSocketFrame binary(byte[] buf)
public static WebSocketFrame ping()
public static WebSocketFrame pong()
public static WebSocketFrame text()
public static WebSocketFrame text(String msg)
public void assertValid()
public int getContinuationIndex()
For every OpCode.CONTINUATION
opcode encountered, this increments by one.
Note: Not part of the Base Framing Protocol / header information.
public ByteBuffer getPayload()
getPayload
in interface Frame
ByteBuffer.slice()
of the payload buffer (to prevent modification of the buffer state). Possibly null if no payload present.
Note: this method is exposed via the immutable Frame.getPayload()
method.
public String getPayloadAsUTF8()
public int getPayloadLength()
getPayloadLength
in interface Frame
public int getPayloadStart()
getPayloadStart
in interface Frame
public Frame.Type getType()
public boolean hasPayload()
hasPayload
in interface Frame
public boolean isContinuation()
isContinuation
in interface Frame
public boolean isControlFrame()
public boolean isDataFrame()
public boolean isLast()
Frame
Frame.isFin()
public boolean isLastFrame()
public int position()
Used by flow control, generator and window sizing.
public int remaining()
Used by flow control, generator and window sizing.
public void reset()
public Frame setContinuation(boolean continuation)
public Frame setContinuationIndex(int continuationIndex)
public WebSocketFrame setFin(boolean fin)
public Frame setMask(byte[] maskingKey)
public Frame setMasked(boolean mask)
public WebSocketFrame setOpCode(byte op)
public WebSocketFrame setPayload(byte[] buf)
buf
- the bytebuffer to setpublic WebSocketFrame setPayload(byte[] buf, int offset, int len)
buf
- the bytebuffer to setpublic WebSocketFrame setPayload(ByteBuffer buf)
The provided buffer will be used as is, no copying of bytes performed.
The provided buffer should be flipped and ready to READ from.
buf
- the bytebuffer to setpublic WebSocketFrame setPayload(String str)
public WebSocketFrame setRsv1(boolean rsv1)
public WebSocketFrame setRsv2(boolean rsv2)
public WebSocketFrame setRsv3(boolean rsv3)
Copyright © 1995-2013 Mort Bay Consulting. All Rights Reserved.