Class FrameHeaderConsumer
java.lang.Object
org.simpleframework.http.socket.service.FrameHeaderConsumer
- All Implemented Interfaces:
FrameHeader
The
FrameHeaderConsumer is used to consume frames from
a connected TCP channel. This is a state machine that can consume
the data one byte at a time until the entire header has been consumed.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intThis determines the count of the mask bytes read.private booleanDetermines if this frame is part of a larger sequence.private intThis represents the length of the frame payload.private byte[]This is the mask that is used to obfuscate client frames.private booleanIf header consumed was from a client frame the data is masked.private byte[]This is the octet that is used to read one byte at a time.private intRequired number of bytes within the frame header.private FrameTypeThis is the frame type which represents the opcode. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()This resets the collector to its original state so that it can be reused.voidconsume(ByteCursor cursor) This consumes frame bytes using the provided cursor.intThis provides the length of the payload within the frame.byte[]getMask()This provides the client mask send with the request.getType()This is used to determine the type of frame.booleanisFinal()This is used to determine if the frame is the final frame in a sequence of fragments or a whole frame.booleanThis is used to determine if the collector has finished.booleanisMasked()This is used to determine if the frame is masked.
-
Field Details
-
type
This is the frame type which represents the opcode. -
masked
private boolean maskedIf header consumed was from a client frame the data is masked. -
last
private boolean lastDetermines if this frame is part of a larger sequence. -
mask
private byte[] maskThis is the mask that is used to obfuscate client frames. -
octet
private byte[] octetThis is the octet that is used to read one byte at a time. -
required
private int requiredRequired number of bytes within the frame header. -
length
private int lengthThis represents the length of the frame payload. -
count
private int countThis determines the count of the mask bytes read.
-
-
Constructor Details
-
FrameHeaderConsumer
public FrameHeaderConsumer()Constructor for theFrameHeaderConsumerobject. This is used to create a consumer to read the bytes that form the frame header from an underlying TCP connection.
-
-
Method Details
-
getLength
public int getLength()This provides the length of the payload within the frame. It is used to determine how much data to consume from the underlying TCP stream in order to recreate the frame to dispatch.- Specified by:
getLengthin interfaceFrameHeader- Returns:
- the number of bytes used in the frame
-
getMask
public byte[] getMask()This provides the client mask send with the request. The mask is a 32 bit value that is used as an XOR bitmask of the client payload. Masking applies only in the client to server direction.- Specified by:
getMaskin interfaceFrameHeader- Returns:
- this returns the 32 bit mask used for this frame
-
getType
This is used to determine the type of frame. Interpretation of this type is outlined in RFC 6455 and can be loosely categorised as control frames and either data or binary frames.- Specified by:
getTypein interfaceFrameHeader- Returns:
- this returns the type of frame that this represents
-
isMasked
public boolean isMasked()This is used to determine if the frame is masked. All client frames should be masked according to RFC 6455. If masked the payload will have its contents bitmasked with a 32 bit value.- Specified by:
isMaskedin interfaceFrameHeader- Returns:
- this returns true if the payload has been masked
-
isFinal
public boolean isFinal()This is used to determine if the frame is the final frame in a sequence of fragments or a whole frame. If this returns false then the frame is a continuation from from a sequence of fragments, otherwise it is a whole frame or the last fragment.- Specified by:
isFinalin interfaceFrameHeader- Returns:
- this returns false if the frame is a fragment
-
consume
This consumes frame bytes using the provided cursor. The consumer acts as a state machine by consuming the data as that data becomes available, this allows it to consume data asynchronously and dispatch once the whole frame has been consumed.- Parameters:
cursor- the cursor to consume the frame data from- Throws:
IOException
-
isFinished
public boolean isFinished()This is used to determine if the collector has finished. If it is not finished the collector will be registered to listen for an I/O intrrupt to read further bytes of the frame.- Returns:
- true if the collector has finished consuming
-
clear
public void clear()This resets the collector to its original state so that it can be reused. Reusing the collector has obvious benefits as it will reduce the amount of memory churn for the server.
-