View Javadoc
1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package io.netty.handler.codec.mqtt;
18  
19  import io.netty.util.CharsetUtil;
20  import io.netty.util.internal.StringUtil;
21  
22  /**
23   * Payload of {@link MqttConnectMessage}
24   */
25  public final class MqttConnectPayload {
26  
27      private final String clientIdentifier;
28      private final String willTopic;
29      private final byte[] willMessage;
30      private final String userName;
31      private final byte[] password;
32  
33      /**
34       * @deprecated use {@link MqttConnectPayload#MqttConnectPayload(String, String, byte[], String, byte[])} instead
35       */
36      @Deprecated
37      public MqttConnectPayload(
38              String clientIdentifier,
39              String willTopic,
40              String willMessage,
41              String userName,
42              String password) {
43          this(
44            clientIdentifier,
45            willTopic,
46            willMessage.getBytes(CharsetUtil.UTF_8),
47            userName,
48            password.getBytes(CharsetUtil.UTF_8));
49      }
50  
51      public MqttConnectPayload(
52              String clientIdentifier,
53              String willTopic,
54              byte[] willMessage,
55              String userName,
56              byte[] password) {
57          this.clientIdentifier = clientIdentifier;
58          this.willTopic = willTopic;
59          this.willMessage = willMessage;
60          this.userName = userName;
61          this.password = password;
62      }
63  
64      public String clientIdentifier() {
65          return clientIdentifier;
66      }
67  
68      public String willTopic() {
69          return willTopic;
70      }
71  
72      /**
73       * @deprecated use {@link MqttConnectPayload#willMessageInBytes()} instead
74       */
75      @Deprecated
76      public String willMessage() {
77          return willMessage == null ? null : new String(willMessage, CharsetUtil.UTF_8);
78      }
79  
80      public byte[] willMessageInBytes() {
81          return willMessage;
82      }
83  
84      public String userName() {
85          return userName;
86      }
87  
88      /**
89       * @deprecated use {@link MqttConnectPayload#passwordInBytes()} instead
90       */
91      @Deprecated
92      public String password() {
93          return password == null ? null : new String(password, CharsetUtil.UTF_8);
94      }
95  
96      public byte[] passwordInBytes() {
97          return password;
98      }
99  
100     @Override
101     public String toString() {
102         return new StringBuilder(StringUtil.simpleClassName(this))
103             .append('[')
104             .append("clientIdentifier=").append(clientIdentifier)
105             .append(", willTopic=").append(willTopic)
106             .append(", willMessage=").append(willMessage)
107             .append(", userName=").append(userName)
108             .append(", password=").append(password)
109             .append(']')
110             .toString();
111     }
112 }