-
public class WebSocketFrame
-
-
Field Summary
Fields Modifier and Type Field Description public final static intframeLengthOverheadprivate byteopcodeprivate Array<byte>payload
-
Constructor Summary
Constructors Constructor Description WebSocketFrame(byte opcode, boolean fin, Array<byte> payload)Initialise a new WebSocketFrame WebSocketFrame(Array<byte> rawFrame)Initialise WebSocketFrame from raw Data WebSocketFrame(InputStream input)Takes an input stream and parses it into a Websocket frame.
-
Method Summary
Modifier and Type Method Description bytegetOpcode()Array<byte>getPayload()booleanisFin()booleanisCloseFlag()Array<byte>encodeFrame()Encodes the this WebSocketFrame into a byte array. static voidappendLengthAndMask(ByteBuffer buffer, int length, Array<byte> mask)Appends the Length and Mask to the buffer static voidappendFinAndOpCode(ByteBuffer buffer, byte opcode, boolean fin)Appends the Fin flag and the OpCode static Array<byte>generateMaskingKey()Generates a random masking key Nothing super secure, but enough for websockets. -
-
Constructor Detail
-
WebSocketFrame
WebSocketFrame(byte opcode, boolean fin, Array<byte> payload)
Initialise a new WebSocketFrame- Parameters:
opcode- WebSocket Opcodefin- If it's finalpayload- The payload
-
WebSocketFrame
WebSocketFrame(Array<byte> rawFrame)
Initialise WebSocketFrame from raw Data- Parameters:
rawFrame- The raw byte buffer
-
WebSocketFrame
WebSocketFrame(InputStream input)
Takes an input stream and parses it into a Websocket frame.- Parameters:
input- The incoming InputStream
-
-
Method Detail
-
getOpcode
byte getOpcode()
-
getPayload
Array<byte> getPayload()
-
isFin
boolean isFin()
-
isCloseFlag
boolean isCloseFlag()
-
encodeFrame
Array<byte> encodeFrame()
Encodes the this WebSocketFrame into a byte array.
-
appendLengthAndMask
static void appendLengthAndMask(ByteBuffer buffer, int length, Array<byte> mask)
Appends the Length and Mask to the buffer
- Parameters:
buffer- the outgoing ByteBufferlength- the length of the framemask- The WebSocket Mask
-
appendFinAndOpCode
static void appendFinAndOpCode(ByteBuffer buffer, byte opcode, boolean fin)
Appends the Fin flag and the OpCode
- Parameters:
buffer- The outgoing bufferopcode- The Websocket OpCodefin- if this is a final frame
-
generateMaskingKey
static Array<byte> generateMaskingKey()
Generates a random masking key Nothing super secure, but enough for websockets.
-
-
-
-