Class FrameHeaderConsumer
- java.lang.Object
-
- org.simpleframework.http.socket.service.FrameHeaderConsumer
-
- All Implemented Interfaces:
FrameHeader
class FrameHeaderConsumer extends java.lang.Object implements FrameHeader
TheFrameHeaderConsumeris 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:
FrameConsumer
-
-
Field Summary
Fields Modifier and Type Field Description private intcountThis determines the count of the mask bytes read.private booleanlastDetermines if this frame is part of a larger sequence.private intlengthThis represents the length of the frame payload.private byte[]maskThis is the mask that is used to obfuscate client frames.private booleanmaskedIf header consumed was from a client frame the data is masked.private byte[]octetThis is the octet that is used to read one byte at a time.private intrequiredRequired number of bytes within the frame header.private FrameTypetypeThis is the frame type which represents the opcode.
-
Constructor Summary
Constructors Constructor Description FrameHeaderConsumer()Constructor for theFrameHeaderConsumerobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()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.intgetLength()This provides the length of the payload within the frame.byte[]getMask()This provides the client mask send with the request.FrameTypegetType()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.booleanisFinished()This is used to determine if the collector has finished.booleanisMasked()This is used to determine if the frame is masked.
-
-
-
Field Detail
-
type
private FrameType type
This is the frame type which represents the opcode.
-
masked
private boolean masked
If header consumed was from a client frame the data is masked.
-
last
private boolean last
Determines if this frame is part of a larger sequence.
-
mask
private byte[] mask
This is the mask that is used to obfuscate client frames.
-
octet
private byte[] octet
This is the octet that is used to read one byte at a time.
-
required
private int required
Required number of bytes within the frame header.
-
length
private int length
This represents the length of the frame payload.
-
count
private int count
This determines the count of the mask bytes read.
-
-
Method Detail
-
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
public FrameType 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
public void consume(ByteCursor cursor) throws java.io.IOException
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:
java.io.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.
-
-