Class FrameEncoder
- java.lang.Object
-
- org.simpleframework.http.socket.service.FrameEncoder
-
class FrameEncoder extends java.lang.ObjectTheFrameEncoderis 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:
FrameConnection
-
-
Field Summary
Fields Modifier and Type Field Description private OutputBarrierbarrierThis is the underlying sender used to send the frames.private ChannelchannelThis is the TCP channel the frames are delivered over.private java.lang.StringcharsetThis is the charset used to encode the text frames with.private TracetraceThis is used to trace the traffic on the channel.
-
Constructor Summary
Constructors Constructor Description FrameEncoder(Request request)Constructor for theFrameEncoderobject.FrameEncoder(Request request, java.lang.String charset)Constructor for theFrameEncoderobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intencode(byte[] data)This is used to encode the provided data as a WebSocket frame as of RFC 6455.intencode(java.lang.String text)This is used to encode the provided data as a WebSocket frame as of RFC 6455.intencode(Frame frame)This is used to encode the provided frame as a WebSocket frame as of RFC 6455.private intencode(FrameType type, byte[] data, boolean last)This is used to encode the provided frame as a WebSocket frame as of RFC 6455.intencode(Reason reason)This is used to encode the provided data as a WebSocket frame as of RFC 6455.
-
-
-
Field Detail
-
barrier
private final OutputBarrier barrier
This is the underlying sender used to send the frames.
-
channel
private final Channel channel
This is the TCP channel the frames are delivered over.
-
trace
private final Trace trace
This is used to trace the traffic on the channel.
-
charset
private final java.lang.String charset
This is the charset used to encode the text frames with.
-
-
Constructor Detail
-
FrameEncoder
public FrameEncoder(Request request)
Constructor for theFrameEncoderobject. 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
public FrameEncoder(Request request, java.lang.String charset)
Constructor for theFrameEncoderobject. 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 Detail
-
encode
public int encode(java.lang.String text) throws java.io.IOExceptionThis 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:
java.io.IOException
-
encode
public int encode(byte[] data) throws java.io.IOExceptionThis 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:
java.io.IOException
-
encode
public int encode(Reason reason) throws java.io.IOException
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:
java.io.IOException
-
encode
public int encode(Frame frame) throws java.io.IOException
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:
java.io.IOException
-
encode
private int encode(FrameType type, byte[] data, boolean last) throws java.io.IOException
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:
java.io.IOException
-
-