Class FrameEncoder
java.lang.Object
org.simpleframework.http.socket.service.FrameEncoder
The
FrameEncoder
is used to encode data as frames as
defined by RFC 6455. This can encode binary, and text frames as
well as control frames. All frames generated are written to the
underlying channel but are not flushed so that multiple frames
can be buffered before the final flush is made.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final OutputBarrier
This is the underlying sender used to send the frames.private final Channel
This is the TCP channel the frames are delivered over.private final String
This is the charset used to encode the text frames with.private final Trace
This is used to trace the traffic on the channel. -
Constructor Summary
ConstructorsConstructorDescriptionFrameEncoder
(Request request) Constructor for theFrameEncoder
object.FrameEncoder
(Request request, String charset) Constructor for theFrameEncoder
object. -
Method Summary
Modifier and TypeMethodDescriptionint
encode
(byte[] data) This is used to encode the provided data as a WebSocket frame as of RFC 6455.int
This is used to encode the provided data as a WebSocket frame as of RFC 6455.int
This is used to encode the provided frame as a WebSocket frame as of RFC 6455.private int
This is used to encode the provided frame as a WebSocket frame as of RFC 6455.int
This is used to encode the provided data as a WebSocket frame as of RFC 6455.
-
Field Details
-
barrier
This is the underlying sender used to send the frames. -
channel
This is the TCP channel the frames are delivered over. -
trace
This is used to trace the traffic on the channel. -
charset
This is the charset used to encode the text frames with.
-
-
Constructor Details
-
FrameEncoder
Constructor for theFrameEncoder
object. This is used to create an encoder to sending frames over the provided channel. Frames send remain unflushed so they can be batched on a single output buffer.- Parameters:
request
- contains the opening handshake information
-
FrameEncoder
Constructor for theFrameEncoder
object. This is used to create an encoder to sending frames over the provided channel. Frames send remain unflushed so they can be batched on a single output buffer.- Parameters:
request
- contains the opening handshake informationcharset
- this is the character encoding to encode with
-
-
Method Details
-
encode
This is used to encode the provided data as a WebSocket frame as of RFC 6455. The encoded data is written to the underlying socket and the number of bytes generated is returned.- Parameters:
text
- this is the data used to encode the frame- Returns:
- the size of the generated frame including the header
- Throws:
IOException
-
encode
This is used to encode the provided data as a WebSocket frame as of RFC 6455. The encoded data is written to the underlying socket and the number of bytes generated is returned.- Parameters:
data
- this is the data used to encode the frame- Returns:
- the size of the generated frame including the header
- Throws:
IOException
-
encode
This is used to encode the provided data as a WebSocket frame as of RFC 6455. The encoded data is written to the underlying socket and the number of bytes generated is returned. A close frame with a reason is similar to a text frame with the exception that the first two bytes of the frame payload contains the close code as a two byte integer in network byte order. The body of the close frame may contain UTF-8 encoded data with a reason, the interpretation of which is not defined by RFC 6455.- Parameters:
reason
- this is the data used to encode the frame- Returns:
- the size of the generated frame including the header
- Throws:
IOException
-
encode
This is used to encode the provided frame as a WebSocket frame as of RFC 6455. The encoded data is written to the underlying socket and the number of bytes generated is returned.- Parameters:
frame
- this is frame that is to be send over the channel- Returns:
- the size of the generated frame including the header
- Throws:
IOException
-
encode
This is used to encode the provided frame as a WebSocket frame as of RFC 6455. The encoded data is written to the underlying socket and the number of bytes generated is returned.- Parameters:
type
- this is the type of frame that is to be encodeddata
- this is the data used to create the framelast
- determines if the is the last frame in a sequence- Returns:
- the size of the generated frame including the header
- Throws:
IOException
-