blob: 03e73040161bbb1401167115c751c0a2ed389be2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package de.measite.minidns.record;
import java.io.DataInputStream;
import java.io.IOException;
import de.measite.minidns.Record.TYPE;
import de.measite.minidns.util.NameUtil;
/**
* TXT record (actually a binary blob with wrappers for text content).
*/
public class TXT implements Data {
protected byte[] blob;
public byte[] getBlob() {
return blob;
}
public void setBlob(byte[] blob) {
this.blob = blob;
}
public String getText() {
try {
return (new String(blob, "UTF-8")).intern();
} catch (Exception e) {
/* Can't happen for UTF-8 unless it's really a blob */
return null;
}
}
public void setText(String text) {
try {
this.blob = text.getBytes("UTF-8");
} catch (Exception e) {
/* Can't happen, UTF-8 IS supported */
throw new RuntimeException("UTF-8 not supported", e);
}
}
@Override
public byte[] toByteArray() {
throw new UnsupportedOperationException("Not implemented yet");
}
@Override
public void parse(DataInputStream dis, byte[] data, int length)
throws IOException
{
blob = new byte[length];
dis.readFully(blob);
}
@Override
public TYPE getType() {
return TYPE.TXT;
}
@Override
public String toString() {
return "\"" + getText() + "\"";
}
}
|