查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2015 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    *   https://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  package io.netty.handler.codec.dns;
17  
18  import io.netty.util.internal.StringUtil;
19  import io.netty.util.internal.UnstableApi;
20  
21  /**
22   * The default {@link DnsQuestion} implementation.
23   */
24  @UnstableApi
25  public class DefaultDnsQuestion extends AbstractDnsRecord implements DnsQuestion {
26  
27      /**
28       * Creates a new {@link #CLASS_IN IN-class} question.
29       *
30       * @param name the domain name of the DNS question
31       * @param type the type of the DNS question
32       */
33      public DefaultDnsQuestion(String name, DnsRecordType type) {
34          super(name, type, 0);
35      }
36  
37      /**
38       * Creates a new question.
39       *
40       * @param name the domain name of the DNS question
41       * @param type the type of the DNS question
42       * @param dnsClass the class of the record, usually one of the following:
43       *                 <ul>
44       *                     <li>{@link #CLASS_IN}</li>
45       *                     <li>{@link #CLASS_CSNET}</li>
46       *                     <li>{@link #CLASS_CHAOS}</li>
47       *                     <li>{@link #CLASS_HESIOD}</li>
48       *                     <li>{@link #CLASS_NONE}</li>
49       *                     <li>{@link #CLASS_ANY}</li>
50       *                 </ul>
51       */
52      public DefaultDnsQuestion(String name, DnsRecordType type, int dnsClass) {
53          super(name, type, dnsClass, 0);
54      }
55  
56      @Override
57      public String toString() {
58          StringBuilder buf = new StringBuilder(64);
59  
60          buf.append(StringUtil.simpleClassName(this))
61             .append('(')
62             .append(name())
63             .append(' ');
64  
65          DnsMessageUtil.appendRecordClass(buf, dnsClass())
66                        .append(' ')
67                        .append(type().name())
68                        .append(')');
69  
70          return buf.toString();
71      }
72  }