diff options
author | Rene Treffer <treffer+github@measite.de> | 2014-06-08 15:37:40 +0200 |
---|---|---|
committer | Rene Treffer <treffer+github@measite.de> | 2014-06-08 15:37:40 +0200 |
commit | f66c0db63f0c0b65ad59ac1a8aaadc1cbaf40761 (patch) | |
tree | d8f8364ccd928865b04056cdf3ac2c77812a5fa7 /src/main/java/de/measite/minidns/Question.java | |
parent | 152be6eb1a22da8cebe24ac4ee05b487936c9f2a (diff) | |
parent | 52807fe7c415e9977cd2d7191b7e1251c9216256 (diff) |
Merge pull request #3 from Flowdalic/androidagnostic
Make minidns Android agnostic
Diffstat (limited to 'src/main/java/de/measite/minidns/Question.java')
-rw-r--r-- | src/main/java/de/measite/minidns/Question.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/main/java/de/measite/minidns/Question.java b/src/main/java/de/measite/minidns/Question.java new file mode 100644 index 00000000..9d1e3f56 --- /dev/null +++ b/src/main/java/de/measite/minidns/Question.java @@ -0,0 +1,62 @@ +package de.measite.minidns; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import de.measite.minidns.Record.CLASS; +import de.measite.minidns.Record.TYPE; +import de.measite.minidns.util.NameUtil; + +public class Question { + + private String name; + + private TYPE type; + + private CLASS clazz = CLASS.IN; + + public TYPE getType() { + return type; + } + + public void setType(TYPE type) { + this.type = type; + } + + public CLASS getClazz() { + return clazz; + } + + public void setClazz(CLASS clazz) { + this.clazz = clazz; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public void parse(DataInputStream dis, byte[] data) throws IOException { + this.name = NameUtil.parse(dis, data); + this.type = TYPE.getType(dis.readUnsignedShort()); + this.clazz = CLASS.getClass(dis.readUnsignedShort()); + } + + public byte[] toByteArray() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(512); + DataOutputStream dos = new DataOutputStream(baos); + + dos.write(NameUtil.toByteArray(this.name)); + dos.writeShort(type.getValue()); + dos.writeShort(clazz.getValue()); + + dos.flush(); + return baos.toByteArray(); + } + +} |