Class ReasonExtractor

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

class ReasonExtractor extends Object
The ReasonExtractor object is used to extract the close reason from a frame payload. If their is no close reason this will return a Reason with just the close code. Finally in the event of a botched frame being sent with no close code then the close code 1005 is used to indicate no reason.
  • Field Details

    • converter

      private final DataConverter converter
      This is the data converter object used to convert data.
  • Constructor Details

    • ReasonExtractor

      public ReasonExtractor()
      Constructor for the ReasonExtractor object. This is used to create an extractor for close code and the close reason descriptions. All descriptions are decoded using the UTF-8 character encoding.
  • Method Details

    • extract

      public Reason extract(Frame frame)
      This is used to extract a reason from the provided frame. The close reason is taken from the first two bytes of the frame payload and the UTF-8 string that follows is the description.
      Parameters:
      frame - this is the frame to extract the reason from
      Returns:
      a reason containing the close code and reason
    • extractText

      private String extractText(byte[] data)
      This method is used to extract the UTF-8 description from the frame payload. If there are only two bytes within the payload then this will return null for the reason.
      Parameters:
      data - the frame payload to extract the description from
      Returns:
      returns the description within the payload
    • extractCode

      private CloseCode extractCode(byte[] data)
      This method is used to extract the close code. The close code is an two byte integer in network byte order at the start of the close frame payload. This code is required by RFC 6455 however if not code is available code 1005 is returned.
      Parameters:
      data - the frame payload to extract the description from
      Returns:
      returns the description within the payload