diff options
author | Rene Treffer <treffer@measite.de> | 2014-07-23 00:00:55 +0200 |
---|---|---|
committer | Rene Treffer <treffer@measite.de> | 2014-07-23 00:01:10 +0200 |
commit | b0f8bec1cbfa6d21e0873c63d5213bd12d429bd8 (patch) | |
tree | c17cf78bb0e76edf823c59b48f13b402329c1962 /src/main/java/de/measite/minidns/record/TXT.java | |
parent | f13813186f7d106ff32e525b2517227108651dd9 (diff) |
Add TXT record
Diffstat (limited to 'src/main/java/de/measite/minidns/record/TXT.java')
-rw-r--r-- | src/main/java/de/measite/minidns/record/TXT.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main/java/de/measite/minidns/record/TXT.java b/src/main/java/de/measite/minidns/record/TXT.java new file mode 100644 index 00000000..03e73040 --- /dev/null +++ b/src/main/java/de/measite/minidns/record/TXT.java @@ -0,0 +1,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() + "\""; + } + +} |