Class MqttCredentials

java.lang.Object
org.mqtt4j.hato.MqttCredentials

public final class MqttCredentials extends Object
Immutable MQTT credentials: a username and an optional binary password. The username is an MQTT UTF-8 string of at most 65535 bytes and may be empty. A password contains at most 65535 bytes and is copied on construction and access. An absent password and an empty password are distinct values. Equality compares password contents. toString() reveals neither credential.
  • Method Details

    • of

      public static MqttCredentials of(String username)
      Creates credentials containing only a username.
      Parameters:
      username - the username, which may be empty
      Returns:
      the credentials
      
      Throws:
      IllegalArgumentException -
      if the username contains U+0000, an unpaired surrogate, or exceeds 65535 bytes in
      UTF-8
      
    • of

      public static MqttCredentials of(String username, byte[] password)
      Creates credentials with a copy of the binary password, which may be empty.
      Parameters:
      username - the username, which may be empty
      password - the password, which may be empty
      Returns:
      the credentials
      
      Throws:
      IllegalArgumentException -
      if the username contains U+0000, an unpaired surrogate, or exceeds 65535 bytes in
      UTF-8, or the password exceeds 65535 bytes
      
    • username

      public String username()
      Returns the username, which may be empty.
      Returns:
      the username, which may be empty
    • password

      public Optional<byte[]> password()
      Returns a copy of the password, or empty when no password was supplied. A supplied zero-length password produces a present result containing an empty array.
      Returns:
      a copy of the password, or empty when no password was supplied
    • equals

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object