1package de.measite.minidns;
2
3import java.io.ByteArrayOutputStream;
4import java.io.DataInputStream;
5import java.io.DataOutputStream;
6import java.io.IOException;
7
8import de.measite.minidns.Record.CLASS;
9import de.measite.minidns.Record.TYPE;
10import de.measite.minidns.util.NameUtil;
11
12public class Question {
13
14 private String name;
15
16 private TYPE type;
17
18 private CLASS clazz = CLASS.IN;
19
20 public TYPE getType() {
21 return type;
22 }
23
24 public void setType(TYPE type) {
25 this.type = type;
26 }
27
28 public CLASS getClazz() {
29 return clazz;
30 }
31
32 public void setClazz(CLASS clazz) {
33 this.clazz = clazz;
34 }
35
36 public String getName() {
37 return name;
38 }
39
40 public void setName(String name) {
41 this.name = name;
42 }
43
44 public void parse(DataInputStream dis, byte[] data) throws IOException {
45 this.name = NameUtil.parse(dis, data);
46 this.type = TYPE.getType(dis.readUnsignedShort());
47 this.clazz = CLASS.getClass(dis.readUnsignedShort());
48 }
49
50 public byte[] toByteArray() throws IOException {
51 ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
52 DataOutputStream dos = new DataOutputStream(baos);
53
54 dos.write(NameUtil.toByteArray(this.name));
55 dos.writeShort(type.getValue());
56 dos.writeShort(clazz.getValue());
57
58 dos.flush();
59 return baos.toByteArray();
60 }
61
62}