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