Class FrameEncoder


  • class FrameEncoder
    extends java.lang.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:
    FrameConnection
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private OutputBarrier barrier
      This is the underlying sender used to send the frames.
      private Channel channel
      This is the TCP channel the frames are delivered over.
      private java.lang.String charset
      This is the charset used to encode the text frames with.
      private Trace trace
      This is used to trace the traffic on the channel.
    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      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​(java.lang.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 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 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,
                            java.lang.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 Detail

      • encode

        public int encode​(java.lang.String text)
                   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.
        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.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:
        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 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:
        java.io.IOException