Class FrameBuilder


  • class FrameBuilder
    extends java.lang.Object
    The FrameBuilder object is used to create an object that interprets a frame header to produce frame objects. For efficiency this converts binary data to the native frame data type, which avoids memory churn.
    See Also:
    FrameConsumer
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private DataConverter converter
      This converts binary data to a UTF-8 string for text frames.
      private FrameHeader header
      This is used to determine the type of frames to create.
    • Constructor Summary

      Constructors 
      Constructor Description
      FrameBuilder​(FrameHeader header)
      Constructor for the FrameBuilder object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Frame create​(byte[] data, int count)
      This is used to create a frame object to represent the data that has been consumed.
      private Frame createBinary​(byte[] data, int count)
      This is used to create a frame object from the provided data.
      private Frame createText​(byte[] data, int count)
      This is used to create a frame object from the provided data.
      • Methods inherited from class java.lang.Object

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

      • converter

        private final DataConverter converter
        This converts binary data to a UTF-8 string for text frames.
      • header

        private final FrameHeader header
        This is used to determine the type of frames to create.
    • Constructor Detail

      • FrameBuilder

        public FrameBuilder​(FrameHeader header)
        Constructor for the FrameBuilder object. This acts as a factory for frame objects by using the provided header to determine the frame type to be created.
        Parameters:
        header - the header used to determine the frame type
    • Method Detail

      • create

        public Frame create​(byte[] data,
                            int count)
        This is used to create a frame object to represent the data that has been consumed. The frame created will contain either a copy of the provided byte buffer or a text string encoded in UTF-8. To avoid memory churn this method should be used sparingly.
        Returns:
        this returns a frame created from the consumed bytes
      • createText

        private Frame createText​(byte[] data,
                                 int count)
        This is used to create a frame object from the provided data. The resulting frame will contain a UTF-8 encoding of the data to ensure that data conversion needs to be performed only once.
        Parameters:
        data - this is the data to convert to a new frame
        count - this is the number of bytes in the frame
        Returns:
        a new frame containing the text
      • createBinary

        private Frame createBinary​(byte[] data,
                                   int count)
        This is used to create a frame object from the provided data. The resulting frame will contain a copy of the data to ensure that the frame is immutable.
        Parameters:
        data - this is the data to convert to a new frame
        count - this is the number of bytes in the frame
        Returns:
        a new frame containing a copy of the provided data