Package ej.websocket

Class ReasonForClosure


  • public final class ReasonForClosure
    extends Object
    A ReasonForClosure is a close code (which is a number) and a close reason (which a String that may be empty).

    As explained in section 7.4. Status Codes, "an endpoint may indicate a reason for closure" when sending a close frame. If it does so, the reason for closure is composed of two parts (section 5.5.1 Close):

    • 'status code' (section 7.4) or 'close code' (section 7.1.5), which is a 2-byte unsigned integer,
    • 'close reason' (section 7.1.6), which may be empty.
    Both are optional (sections 5.5.1 and 7.4) but it is not possible to have a close reason without a close code (sections 5.5.1 and 7.1.6.). Hence, the payload of the close frame may be:
    • empty (no close code, no close reason),
    • 2-byte long (close code, but no close reason),
    • more than 2-byte long (close code, close reason).
    When no close code is given in the closing frame, it is considered to be 1005 (section 7.1.5). When no close reason is given in the closing frame, it is the empty string (section 7.1.6).
    See Also:
    CloseCodes
    • Constructor Detail

      • ReasonForClosure

        public ReasonForClosure​(int code,
                                String reason)
        Parameters:
        code - the close code
        reason - a message that describes why the connection has been closed. It may be empty. If it is null, it is converted to the empty string.
        See Also:
        CloseCodes
    • Method Detail

      • getCloseCode

        public int getCloseCode()
        Get the close code.
        Returns:
        the close code
      • setCode

        public ReasonForClosure setCode​(int code)
        Change the close code.
        Parameters:
        code - the new code
        Returns:
        this
      • getCloseReason

        public String getCloseReason()
        Get the close reason (may be an empty string).
        Returns:
        a message that describes why the connection has been closed
      • setReason

        public ReasonForClosure setReason​(String reason)
        Change the close reason.
        Parameters:
        reason - the new reason message. It may be empty. If it is null, it is converted to the empty string.
        Returns:
        this
      • toString

        public String toString()
        Description copied from class: Object
        Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

        The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

         getClass().getName() + '@' + Integer.toHexString(hashCode())
         
        Overrides:
        toString in class Object
        Returns:
        a string representation of the object.