Class Frame

java.lang.Object
org.eclipse.jetty.websocket.core.Frame
Direct Known Subclasses:
Parser.ParsedFrame

public class Frame extends Object
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 Details

    • MAX_CONTROL_PAYLOAD

      public static final int MAX_CONTROL_PAYLOAD
      Maximum size of Control frame, per RFC 6455
      See Also:
    • 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
       
    • mask

      protected byte[] mask
    • payload

      protected ByteBuffer payload
      The payload data.

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

  • Constructor Details

    • Frame

      public Frame(byte opcode)
      Construct form opcode
      Parameters:
      opcode - the opcode the frame is based on
    • Frame

      public Frame(byte opCode, ByteBuffer payload)
    • Frame

      public Frame(byte opCode, String payload)
    • Frame

      public Frame(byte opCode, boolean fin, ByteBuffer payload)
    • Frame

      public Frame(byte opCode, boolean fin, String payload)
    • Frame

      protected Frame()
    • Frame

      public Frame(byte finRsvOp, byte[] mask, ByteBuffer payload)
  • Method Details

    • copyWithoutPayload

      public static Frame copyWithoutPayload(Frame original)
    • copy

      public static Frame copy(Frame original)
    • isControlFrame

      public boolean isControlFrame()
    • isDataFrame

      public boolean isDataFrame()
    • copyHeaders

      protected void copyHeaders(Frame frame)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getMask

      public byte[] getMask()
    • getOpCode

      public byte getOpCode()
    • getPayload

      public ByteBuffer getPayload()
      Get the payload ByteBuffer.
    • getPayloadAsUTF8

      public String getPayloadAsUTF8()
      Get the payload of the frame as a UTF-8 string.

      Should only be used in testing, does not validate the UTF-8 and a non fin frame can contain partial UTF-8 characters.

      Returns:
      the payload as a UTF-8 string.
    • getPayloadLength

      public int getPayloadLength()
    • hashCode

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

      public boolean hasPayload()
    • isFin

      public boolean isFin()
    • isMasked

      public boolean isMasked()
    • isRsv1

      public boolean isRsv1()
    • isRsv2

      public boolean isRsv2()
    • isRsv3

      public boolean isRsv3()
    • reset

      public void reset()
    • setFin

      public Frame setFin(boolean fin)
    • setMask

      public Frame setMask(byte[] maskingKey)
    • setOpCode

      protected Frame setOpCode(byte op)
    • setPayload

      public Frame setPayload(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
    • setPayload

      public Frame setPayload(String str)
    • setPayload

      public Frame setPayload(byte[] buf)
    • setRsv1

      public Frame setRsv1(boolean rsv1)
    • setRsv2

      public Frame setRsv2(boolean rsv2)
    • setRsv3

      public Frame setRsv3(boolean rsv3)
    • asReadOnly

      public Frame asReadOnly()
    • hasRsv

      public boolean hasRsv()
    • demask

      public void demask()
    • toString

      public String toString()
      Overrides:
      toString in class Object