diff options
author | Rene Treffer <treffer@measite.de> | 2014-06-22 15:29:51 +0200 |
---|---|---|
committer | Rene Treffer <treffer@measite.de> | 2014-06-22 15:29:51 +0200 |
commit | 0e484dd17f85d923891460ff606b13294e8985ba (patch) | |
tree | 01b3835385c9338aec7fb9bdaf5361a25d8b5568 /src/main/java/de/measite/minidns/Question.java | |
parent | 028700efe0345e764f598378cb64c5e57f980e33 (diff) |
Add missing javadoc and review new code
Diffstat (limited to 'src/main/java/de/measite/minidns/Question.java')
-rw-r--r-- | src/main/java/de/measite/minidns/Question.java | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/src/main/java/de/measite/minidns/Question.java b/src/main/java/de/measite/minidns/Question.java index 8efe19f1..62862251 100644 --- a/src/main/java/de/measite/minidns/Question.java +++ b/src/main/java/de/measite/minidns/Question.java @@ -4,39 +4,89 @@ import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.util.Arrays; import de.measite.minidns.Record.CLASS; import de.measite.minidns.Record.TYPE; import de.measite.minidns.util.NameUtil; +/** + * A DNS question (request). + */ public class Question { + /** + * The question string (e.g. "measite.de"). + */ private final String name; + /** + * The question type (e.g. A). + */ private final TYPE type; + /** + * The question class (usually IN / internet). + */ private final CLASS clazz; + /** + * Cache for the serialized object. + */ private byte[] byteArray; + /** + * Create a dns question for the given name/type/class. + * @param name The name e.g. "measite.de". + * @param type The type, e.g. A. + * @param clazz The class, usually IN (internet). + */ public Question(String name, TYPE type, CLASS clazz) { this.name = name; this.type = type; this.clazz = clazz; } + /** + * Create a dns question for the given name/type/IN (internet class). + * @param name The name e.g. "measite.de". + * @param type The type, e.g. A. + */ + public Question(String name, TYPE type) { + this(name, type, CLASS.IN); + } + + /** + * Retrieve the type of this question. + * @return The type. + */ public TYPE getType() { return type; } + /** + * Retrieve the class of this dns question (usually internet). + * @return The class of this dns question. + */ public CLASS getClazz() { return clazz; } + /** + * Retrieve the name of this dns question (e.g. "measite.de"). + * @return The name of this dns question. + */ public String getName() { return name; } + /** + * Parse a byte array and rebuild the dns question from it. + * @param dis The input stream. + * @param data The plain data (for dns name references). + * @return The parsed dns question. + * @throws IOException On errors (read outside of packet). + */ public static Question parse(DataInputStream dis, byte[] data) throws IOException { String name = NameUtil.parse(dis, data); TYPE type = TYPE.getType(dis.readUnsignedShort()); @@ -44,6 +94,10 @@ public class Question { return new Question (name, type, clazz); } + /** + * Generate a binary paket for this dns question. + * @return The dns question. + */ public byte[] toByteArray() { if (byteArray == null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(512); @@ -65,7 +119,7 @@ public class Question { @Override public int hashCode() { - return toByteArray().hashCode(); + return Arrays.hashCode(toByteArray()); } @Override @@ -76,6 +130,8 @@ public class Question { if (!(other instanceof Question)) { return false; } - return this.hashCode() == other.hashCode(); + byte t[] = toByteArray(); + byte o[] = ((Question)other).toByteArray(); + return Arrays.equals(t, o); } } |