1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.dns;
17
18 import io.netty.buffer.ByteBuf;
19 import io.netty.util.internal.StringUtil;
20 import io.netty.util.internal.UnstableApi;
21
22 import static io.netty.util.internal.ObjectUtil.checkNotNull;
23
24
25
26
27 @UnstableApi
28 public class DefaultDnsRawRecord extends AbstractDnsRecord implements DnsRawRecord {
29
30 private final ByteBuf content;
31
32
33
34
35
36
37
38
39 public DefaultDnsRawRecord(String name, DnsRecordType type, long timeToLive, ByteBuf content) {
40 this(name, type, DnsRecord.CLASS_IN, timeToLive, content);
41 }
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 public DefaultDnsRawRecord(
60 String name, DnsRecordType type, int dnsClass, long timeToLive, ByteBuf content) {
61 super(name, type, dnsClass, timeToLive);
62 this.content = checkNotNull(content, "content");
63 }
64
65 @Override
66 public ByteBuf content() {
67 return content;
68 }
69
70 @Override
71 public DnsRawRecord copy() {
72 return replace(content().copy());
73 }
74
75 @Override
76 public DnsRawRecord duplicate() {
77 return replace(content().duplicate());
78 }
79
80 @Override
81 public DnsRawRecord retainedDuplicate() {
82 return replace(content().retainedDuplicate());
83 }
84
85 @Override
86 public DnsRawRecord replace(ByteBuf content) {
87 return new DefaultDnsRawRecord(name(), type(), dnsClass(), timeToLive(), content);
88 }
89
90 @Override
91 public int refCnt() {
92 return content().refCnt();
93 }
94
95 @Override
96 public DnsRawRecord retain() {
97 content().retain();
98 return this;
99 }
100
101 @Override
102 public DnsRawRecord retain(int increment) {
103 content().retain(increment);
104 return this;
105 }
106
107 @Override
108 public boolean release() {
109 return content().release();
110 }
111
112 @Override
113 public boolean release(int decrement) {
114 return content().release(decrement);
115 }
116
117 @Override
118 public DnsRawRecord touch() {
119 content().touch();
120 return this;
121 }
122
123 @Override
124 public DnsRawRecord touch(Object hint) {
125 content().touch(hint);
126 return this;
127 }
128
129 @Override
130 public String toString() {
131 final StringBuilder buf = new StringBuilder(64).append(StringUtil.simpleClassName(this)).append('(');
132 final DnsRecordType type = type();
133 if (type != DnsRecordType.OPT) {
134 buf.append(name().isEmpty()? "<root>" : name())
135 .append(' ')
136 .append(timeToLive())
137 .append(' ');
138
139 DnsMessageUtil.appendRecordClass(buf, dnsClass())
140 .append(' ')
141 .append(type.name());
142 } else {
143 buf.append("OPT flags:")
144 .append(timeToLive())
145 .append(" udp:")
146 .append(dnsClass());
147 }
148
149 buf.append(' ')
150 .append(content().readableBytes())
151 .append("B)");
152
153 return buf.toString();
154 }
155 }