Class FrameEncoder

java.lang.Object
org.simpleframework.http.socket.service.FrameEncoder

class FrameEncoder extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    private 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

    Constructors
    Constructor
    Description
    Constructor for the FrameEncoder object.
    FrameEncoder(Request request, String charset)
    Constructor for the FrameEncoder object.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    encode(byte[] data)
    This is used to encode the provided data as a WebSocket frame as of RFC 6455.
    int
    encode(String text)
    This is used to encode the provided data as a WebSocket frame as of RFC 6455.
    int
    encode(Frame frame)
    This is used to encode the provided frame as a WebSocket frame as of RFC 6455.
    private int
    encode(FrameType type, byte[] data, boolean last)
    This is used to encode the provided frame as a WebSocket frame as of RFC 6455.
    int
    encode(Reason reason)
    This is used to encode the provided data as a WebSocket frame as of RFC 6455.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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 String charset
      This is the charset used to encode the text frames with.
  • Constructor Details

    • FrameEncoder

      public FrameEncoder(Request request)
      Constructor for the FrameEncoder 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

      public FrameEncoder(Request request, String charset)
      Constructor for the FrameEncoder 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
      charset - this is the character encoding to encode with
  • Method Details

    • encode

      public int encode(String text) throws 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.
      Parameters:
      text - this is the data used to encode the frame
      Returns:
      the size of the generated frame including the header
      Throws:
      IOException
    • encode

      public int encode(byte[] data) throws 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.
      Parameters:
      data - this is the data used to encode the frame
      Returns:
      the size of the generated frame including the header
      Throws:
      IOException
    • encode

      public int encode(Reason reason) throws 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:
      IOException
    • encode

      public int encode(Frame frame) throws 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:
      IOException
    • encode

      private int encode(FrameType type, byte[] data, boolean last) throws 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 encoded
      data - this is the data used to create the frame
      last - determines if the is the last frame in a sequence
      Returns:
      the size of the generated frame including the header
      Throws:
      IOException