Class WebSocketFrame

  • All Implemented Interfaces:
    Frame
    Direct Known Subclasses:
    ControlFrame, DataFrame

    public abstract class WebSocketFrame
    extends java.lang.Object
    implements Frame
    A Base Frame as seen in RFC 6455. Sec 5.2
        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 ...                |
       +---------------------------------------------------------------+
     
    • Field Detail

      • finRsvOp

        protected byte finRsvOp
        Combined FIN + RSV1 + RSV2 + RSV3 + OpCode byte.
           1000_0000 (0x80) = fin
           0100_0000 (0x40) = rsv1
           0010_0000 (0x20) = rsv2
           0001_0000 (0x10) = rsv3
           0000_1111 (0x0F) = opcode
         
      • masked

        protected boolean masked
      • mask

        protected byte[] mask
      • data

        protected java.nio.ByteBuffer data
        The payload data.

        It is assumed to always be in FLUSH mode (ready to read) in this object.

    • Constructor Detail

      • WebSocketFrame

        protected WebSocketFrame​(byte opcode)
        Construct form opcode
        Parameters:
        opcode - the opcode the frame is based on
    • Method Detail

      • assertValid

        public abstract void assertValid()
      • copyHeaders

        protected void copyHeaders​(Frame frame)
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • getMask

        public byte[] getMask()
        Specified by:
        getMask in interface Frame
      • getOpCode

        public final byte getOpCode()
        Specified by:
        getOpCode in interface Frame
      • getPayload

        public java.nio.ByteBuffer getPayload()
        Get the payload ByteBuffer. possible null.
        Specified by:
        getPayload in interface Frame
      • getPayloadAsUTF8

        public java.lang.String getPayloadAsUTF8()
      • getPayloadLength

        public int getPayloadLength()
        Description copied from interface: Frame
        The original payload length (Buffer.remaining())
        Specified by:
        getPayloadLength in interface Frame
        Returns:
        the original payload length (Buffer.remaining())
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • hasPayload

        public boolean hasPayload()
        Specified by:
        hasPayload in interface Frame
      • isControlFrame

        public abstract boolean isControlFrame()
      • isDataFrame

        public abstract boolean isDataFrame()
      • isFin

        public boolean isFin()
        Specified by:
        isFin in interface Frame
      • isLast

        public boolean isLast()
        Description copied from interface: Frame
        Specified by:
        isLast in interface Frame
        Returns:
        true if final frame.
      • isMasked

        public boolean isMasked()
        Specified by:
        isMasked in interface Frame
      • isRsv1

        public boolean isRsv1()
        Specified by:
        isRsv1 in interface Frame
      • isRsv2

        public boolean isRsv2()
        Specified by:
        isRsv2 in interface Frame
      • isRsv3

        public boolean isRsv3()
        Specified by:
        isRsv3 in interface Frame
      • reset

        public void reset()
      • setMask

        public Frame setMask​(byte[] maskingKey)
      • setMasked

        public Frame setMasked​(boolean mask)
      • setPayload

        public WebSocketFrame setPayload​(java.nio.ByteBuffer buf)
        Set the data payload.

        The provided buffer will be used as is, no copying of bytes performed.

        The provided buffer should be flipped and ready to READ from.

        Parameters:
        buf - the bytebuffer to set
        Returns:
        the frame itself
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object