aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/measite/minidns/util/NameUtil.java
diff options
context:
space:
mode:
authorRene Treffer <treffer@measite.de>2014-06-22 15:29:51 +0200
committerRene Treffer <treffer@measite.de>2014-06-22 15:29:51 +0200
commit0e484dd17f85d923891460ff606b13294e8985ba (patch)
tree01b3835385c9338aec7fb9bdaf5361a25d8b5568 /src/main/java/de/measite/minidns/util/NameUtil.java
parent028700efe0345e764f598378cb64c5e57f980e33 (diff)
Add missing javadoc and review new code
Diffstat (limited to '')
-rw-r--r--src/main/java/de/measite/minidns/util/NameUtil.java40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/main/java/de/measite/minidns/util/NameUtil.java b/src/main/java/de/measite/minidns/util/NameUtil.java
index 91a6649d..7ae373bc 100644
--- a/src/main/java/de/measite/minidns/util/NameUtil.java
+++ b/src/main/java/de/measite/minidns/util/NameUtil.java
@@ -8,12 +8,28 @@ import java.net.IDN;
import java.util.HashSet;
import java.util.Arrays;
+/**
+ * Utilities related to internationalized domain names and dns name handling.
+ */
public class NameUtil {
+ /**
+ * Retrieve the rough binary length of a string
+ * (length + 2 bytes length prefix).
+ * @param name The name string.
+ * @return The binary size of the string (length + 2).
+ */
public static int size(String name) {
return name.length() + 2;
}
+ /**
+ * Check if two internationalized domain names are equal, possibly causing
+ * a serialization of both domain names.
+ * @param name1 The first domain name.
+ * @param name2 The second domain name.
+ * @return True if both domain names are the same.
+ */
public static boolean idnEquals(String name1, String name2) {
if (name1 == name2) return true; // catches null, null
if (name1 == null) return false;
@@ -27,6 +43,12 @@ public class NameUtil {
}
}
+ /**
+ * Serialize a domain name under IDN rules.
+ * @param name The domain name.
+ * @return The binary domain name representation.
+ * @throws IOException Should never happen.
+ */
public static byte[] toByteArray(String name) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
DataOutputStream dos = new DataOutputStream(baos);
@@ -38,8 +60,16 @@ public class NameUtil {
dos.writeByte(0);
dos.flush();
return baos.toByteArray();
- }
+ }
+ /**
+ * Parse a domain name starting at the current offset and moving the input
+ * stream pointer past this domain name (even if cross references occure).
+ * @param dis The input stream.
+ * @param data The raw data (for cross references).
+ * @return The domain name string.
+ * @throws IOException Should never happen.
+ */
public static String parse(DataInputStream dis, byte data[])
throws IOException
{
@@ -63,6 +93,14 @@ public class NameUtil {
return s;
}
+ /**
+ * Parse a domain name starting at the given offset.
+ * @param data The raw data.
+ * @param offset The offset.
+ * @param jumps The list of jumps (by now).
+ * @return The parsed domain name.
+ * @throws IllegalStateException on cycles.
+ */
public static String parse(
byte data[],
int offset,