Class MqttCredentials
java.lang.Object
org.mqtt4j.hato.MqttCredentials
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 Summary
Modifier and TypeMethodDescriptionbooleaninthashCode()static MqttCredentialsCreates credentials containing only a username.static MqttCredentialsCreates credentials with a copy of the binary password, which may be empty.Optional<byte[]> password()Returns a copy of the password, or empty when no password was supplied.toString()username()Returns the username, which may be empty.
-
Method Details
-
of
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
Creates credentials with a copy of the binary password, which may be empty.- Parameters:
username- the username, which may be emptypassword- 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
Returns the username, which may be empty.- Returns:
- the username, which may be empty
-
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
-
hashCode
-
toString
-