Top Description Inners Fields Constructors Methods
org.eclipse.jetty.websocket.core

public Class Frame

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jetty.websocket.core.Frame.ReadOnly, org.eclipse.jetty.websocket.core.Frame.Parsed, org.eclipse.jetty.websocket.core.CloseStatus.CloseFrame
Imports
java.io.Closeable, java.nio.ByteBuffer, java.util.Arrays, org.eclipse.jetty.util.BufferUtil, .StringUtil

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 ...                |
  +---------------------------------------------------------------+

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
private static class
Frame.ReadOnly

Immutable, Read-only, Frame implementation.

Field Summary

Modifier and TypeField and Description
protected byte
finRsvOp

Combined FIN + RSV1 + RSV2 + RSV3 + OpCode byte.

protected byte[]
public static final int
MAX_CONTROL_PAYLOAD

Maximum size of Control frame, per RFC 6455

protected ByteBuffer
payload

The payload data.

Constructor Summary

AccessConstructor and Description
public
Frame(byte
the opcode the frame is based on
opcode
)

Construct form opcode

public
Frame(byte opCode, ByteBuffer payload)

public
Frame(byte opCode, String payload)

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

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

protected
public
Frame(byte finRsvOp, byte[] mask, ByteBuffer payload)

Method Summary

Modifier and TypeMethod and Description
public Frame
public static Frame
copy(Frame original)

protected void
public static Frame
public void
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public byte[]
public byte
public ByteBuffer
getPayload()

Get the payload ByteBuffer.

public String

Returns:

the payload as a UTF-8 string.
getPayloadAsUTF8
()

Get the payload of the frame as a UTF-8 string.

public int
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public void
public Frame
setFin(boolean fin)

public Frame
setMask(byte[] maskingKey)

protected Frame
setOpCode(byte op)

public Frame

Returns:

the frame itself
setPayload
(ByteBuffer
the bytebuffer to set
buf
)

Set the data payload.

public Frame
public Frame
setPayload(byte[] buf)

public Frame
setRsv1(boolean rsv1)

public Frame
setRsv2(boolean rsv2)

public Frame
setRsv3(boolean rsv3)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

finRsvOpback to summary
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
maskback to summary
protected byte[] mask
MAX_CONTROL_PAYLOADback to summary
public static final int MAX_CONTROL_PAYLOAD

Maximum size of Control frame, per RFC 6455

payloadback to summary
protected ByteBuffer payload

The payload data.

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

Constructor Detail

Frameback to summary
public Frame(byte opcode)

Construct form opcode

Parameters
opcode:byte

the opcode the frame is based on

Frameback to summary
public Frame(byte opCode, ByteBuffer payload)
Frameback to summary
public Frame(byte opCode, String payload)
Frameback to summary
public Frame(byte opCode, boolean fin, ByteBuffer payload)
Frameback to summary
public Frame(byte opCode, boolean fin, String payload)
Frameback to summary
protected Frame()
Frameback to summary
public Frame(byte finRsvOp, byte[] mask, ByteBuffer payload)

Method Detail

asReadOnlyback to summary
public Frame asReadOnly()
copyback to summary
public static Frame copy(Frame original)
copyHeadersback to summary
protected void copyHeaders(Frame frame)
copyWithoutPayloadback to summary
public static Frame copyWithoutPayload(Frame original)
demaskback to summary
public void demask()
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getMaskback to summary
public byte[] getMask()
getOpCodeback to summary
public byte getOpCode()
getPayloadback to summary
public ByteBuffer getPayload()

Get the payload ByteBuffer.

getPayloadAsUTF8back to summary
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:String

the payload as a UTF-8 string.

getPayloadLengthback to summary
public int getPayloadLength()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
hasPayloadback to summary
public boolean hasPayload()
hasRsvback to summary
public boolean hasRsv()
isControlFrameback to summary
public boolean isControlFrame()
isDataFrameback to summary
public boolean isDataFrame()
isFinback to summary
public boolean isFin()
isMaskedback to summary
public boolean isMasked()
isRsv1back to summary
public boolean isRsv1()
isRsv2back to summary
public boolean isRsv2()
isRsv3back to summary
public boolean isRsv3()
resetback to summary
public void reset()
setFinback to summary
public Frame setFin(boolean fin)
setMaskback to summary
public Frame setMask(byte[] maskingKey)
setOpCodeback to summary
protected Frame setOpCode(byte op)
setPayloadback to summary
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:ByteBuffer

the bytebuffer to set

Returns:Frame

the frame itself

setPayloadback to summary
public Frame setPayload(String str)
setPayloadback to summary
public Frame setPayload(byte[] buf)
setRsv1back to summary
public Frame setRsv1(boolean rsv1)
setRsv2back to summary
public Frame setRsv2(boolean rsv2)
setRsv3back to summary
public Frame setRsv3(boolean rsv3)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.eclipse.jetty.websocket.core back to summary

public Class Frame.Parsed

extends Frame
implements Closeable, Supplier
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.websocket.core.CloseStatus.Supplier, java.io.Closeable, java.lang.AutoCloseable

Field Summary

Modifier and TypeField and Description
pack-priv final CloseStatus
pack-priv final Runnable
Inherited from org.eclipse.jetty.websocket.core.Frame:
finRsvOpmaskMAX_CONTROL_PAYLOADpayload

Constructor Summary

AccessConstructor and Description
public
Parsed(byte firstByte, byte[] mask, ByteBuffer payload, Runnable releaser)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public CloseStatus
public boolean
public String
toString()

Overrides org.eclipse.jetty.websocket.core.Frame.toString.

Returns a string representation of the object.

Inherited from org.eclipse.jetty.websocket.core.Frame:
asReadOnlycopycopyHeaderscopyWithoutPayloaddemaskequalsgetMaskgetOpCodegetPayloadgetPayloadAsUTF8getPayloadLengthhashCodehasPayloadhasRsvisControlFrameisDataFrameisFinisMaskedisRsv1isRsv2isRsv3resetsetFinsetMasksetOpCodesetPayloadsetPayloadsetPayloadsetRsv1setRsv2setRsv3

Field Detail

closeStatusback to summary
pack-priv final CloseStatus closeStatus
releaserback to summary
pack-priv final Runnable releaser

Constructor Detail

Parsedback to summary
public Parsed(byte firstByte, byte[] mask, ByteBuffer payload, Runnable releaser)

Method Detail

closeback to summary
public void close()

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
getCloseStatusback to summary
public CloseStatus getCloseStatus()

Implements org.eclipse.jetty.websocket.core.CloseStatus.Supplier.getCloseStatus.

Annotations
@Override
isReleaseableback to summary
public boolean isReleaseable()
toStringback to summary
public String toString()

Overrides org.eclipse.jetty.websocket.core.Frame.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.eclipse.jetty.websocket.core back to summary

private Class Frame.ReadOnly

extends Frame
Class Inheritance

Immutable, Read-only, Frame implementation.

Field Summary

Inherited from org.eclipse.jetty.websocket.core.Frame:
finRsvOpmaskMAX_CONTROL_PAYLOADpayload

Constructor Summary

AccessConstructor and Description
private
ReadOnly(Frame frame)

Method Summary

Modifier and TypeMethod and Description
public Frame
protected void
public ByteBuffer
getPayload()

Overrides org.eclipse.jetty.websocket.core.Frame.getPayload.

Get the payload ByteBuffer.

public void
public Frame
public Frame
protected Frame
public Frame
setPayload(ByteBuffer
the bytebuffer to set
buf
)

Overrides org.eclipse.jetty.websocket.core.Frame.setPayload.

Set the data payload.

public Frame
public Frame
public Frame
public Frame
public Frame
Inherited from org.eclipse.jetty.websocket.core.Frame:
copycopyWithoutPayloaddemaskequalsgetMaskgetOpCodegetPayloadAsUTF8getPayloadLengthhashCodehasPayloadhasRsvisControlFrameisDataFrameisFinisMaskedisRsv1isRsv2isRsv3toString

Constructor Detail

ReadOnlyback to summary
private ReadOnly(Frame frame)

Method Detail

asReadOnlyback to summary
public Frame asReadOnly()

Overrides org.eclipse.jetty.websocket.core.Frame.asReadOnly.

Annotations
@Override
copyHeadersback to summary
protected void copyHeaders(Frame frame)

Overrides org.eclipse.jetty.websocket.core.Frame.copyHeaders.

Annotations
@Override
getPayloadback to summary
public ByteBuffer getPayload()

Overrides org.eclipse.jetty.websocket.core.Frame.getPayload.

Doc from org.eclipse.jetty.websocket.core.Frame.getPayload.

Get the payload ByteBuffer.

Annotations
@Override
resetback to summary
public void reset()

Overrides org.eclipse.jetty.websocket.core.Frame.reset.

Annotations
@Override
setFinback to summary
public Frame setFin(boolean fin)

Overrides org.eclipse.jetty.websocket.core.Frame.setFin.

Annotations
@Override
setMaskback to summary
public Frame setMask(byte[] maskingKey)

Overrides org.eclipse.jetty.websocket.core.Frame.setMask.

Annotations
@Override
setOpCodeback to summary
protected Frame setOpCode(byte op)

Overrides org.eclipse.jetty.websocket.core.Frame.setOpCode.

Annotations
@Override
setPayloadback to summary
public Frame setPayload(ByteBuffer buf)

Overrides org.eclipse.jetty.websocket.core.Frame.setPayload.

Doc from org.eclipse.jetty.websocket.core.Frame.setPayload.

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:ByteBuffer

the bytebuffer to set

Returns:Frame

the frame itself

Annotations
@Override
setPayloadback to summary
public Frame setPayload(String str)

Overrides org.eclipse.jetty.websocket.core.Frame.setPayload.

Annotations
@Override
setPayloadback to summary
public Frame setPayload(byte[] buf)

Overrides org.eclipse.jetty.websocket.core.Frame.setPayload.

Annotations
@Override
setRsv1back to summary
public Frame setRsv1(boolean rsv1)

Overrides org.eclipse.jetty.websocket.core.Frame.setRsv1.

Annotations
@Override
setRsv2back to summary
public Frame setRsv2(boolean rsv2)

Overrides org.eclipse.jetty.websocket.core.Frame.setRsv2.

Annotations
@Override
setRsv3back to summary
public Frame setRsv3(boolean rsv3)

Overrides org.eclipse.jetty.websocket.core.Frame.setRsv3.

Annotations
@Override