Add an IDN equals method to check names
This commit is contained in:
parent
7d086eaf1a
commit
8a8a7f3b0d
|
@ -6,6 +6,7 @@ import java.io.DataOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.net.IDN;
|
||||
import java.util.HashSet;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class NameUtil {
|
||||
|
||||
|
@ -13,6 +14,19 @@ public class NameUtil {
|
|||
return name.length() + 2;
|
||||
}
|
||||
|
||||
public static boolean idnEquals(String name1, String name2) {
|
||||
if (name1 == name2) return true; // catches null, null
|
||||
if (name1 == null) return false;
|
||||
if (name2 == null) return false;
|
||||
if (name1.equals(name2)) return true;
|
||||
|
||||
try {
|
||||
return Arrays.equals(toByteArray(name1),toByteArray(name2));
|
||||
} catch (IOException e) {
|
||||
return false; // impossible
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] toByteArray(String name) throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
|
||||
DataOutputStream dos = new DataOutputStream(baos);
|
||||
|
|
Loading…
Reference in a new issue