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