1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.netty.handler.codec.mqtt;
18
19 import java.util.Arrays;
20
21 import io.netty.util.CharsetUtil;
22 import io.netty.util.internal.StringUtil;
23
24
25
26
27 public final class MqttConnectPayload {
28
29 private final String clientIdentifier;
30 private final MqttProperties willProperties;
31 private final String willTopic;
32 private final byte[] willMessage;
33 private final String userName;
34 private final byte[] password;
35
36
37
38
39
40 @Deprecated
41 public MqttConnectPayload(
42 String clientIdentifier,
43 String willTopic,
44 String willMessage,
45 String userName,
46 String password) {
47 this(
48 clientIdentifier,
49 MqttProperties.NO_PROPERTIES,
50 willTopic,
51 willMessage.getBytes(CharsetUtil.UTF_8),
52 userName,
53 password.getBytes(CharsetUtil.UTF_8));
54 }
55
56 public MqttConnectPayload(
57 String clientIdentifier,
58 String willTopic,
59 byte[] willMessage,
60 String userName,
61 byte[] password) {
62 this(clientIdentifier,
63 MqttProperties.NO_PROPERTIES,
64 willTopic,
65 willMessage,
66 userName,
67 password);
68 }
69
70 public MqttConnectPayload(
71 String clientIdentifier,
72 MqttProperties willProperties,
73 String willTopic,
74 byte[] willMessage,
75 String userName,
76 byte[] password) {
77 this.clientIdentifier = clientIdentifier;
78 this.willProperties = MqttProperties.withEmptyDefaults(willProperties);
79 this.willTopic = willTopic;
80 this.willMessage = willMessage;
81 this.userName = userName;
82 this.password = password;
83 }
84
85 public String clientIdentifier() {
86 return clientIdentifier;
87 }
88
89 public MqttProperties willProperties() {
90 return willProperties;
91 }
92
93 public String willTopic() {
94 return willTopic;
95 }
96
97
98
99
100 @Deprecated
101 public String willMessage() {
102 return willMessage == null ? null : new String(willMessage, CharsetUtil.UTF_8);
103 }
104
105 public byte[] willMessageInBytes() {
106 return willMessage;
107 }
108
109 public String userName() {
110 return userName;
111 }
112
113
114
115
116 @Deprecated
117 public String password() {
118 return password == null ? null : new String(password, CharsetUtil.UTF_8);
119 }
120
121 public byte[] passwordInBytes() {
122 return password;
123 }
124
125 @Override
126 public String toString() {
127 return new StringBuilder(StringUtil.simpleClassName(this))
128 .append('[')
129 .append("clientIdentifier=").append(clientIdentifier)
130 .append(", willTopic=").append(willTopic)
131 .append(", willMessage=").append(Arrays.toString(willMessage))
132 .append(", userName=").append(userName)
133 .append(", password=").append(Arrays.toString(password))
134 .append(']')
135 .toString();
136 }
137 }