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