|
@@ -22,13 +22,12 @@
|
22
|
22
|
package com.dmdirc.parser.common;
|
23
|
23
|
|
24
|
24
|
import java.util.ArrayList;
|
25
|
|
-import java.util.Hashtable;
|
|
25
|
+import java.util.HashMap;
|
26
|
26
|
import java.util.List;
|
27
|
27
|
|
28
|
28
|
import javax.naming.NamingEnumeration;
|
29
|
29
|
import javax.naming.NamingException;
|
30
|
30
|
import javax.naming.directory.Attribute;
|
31
|
|
-import javax.naming.directory.InitialDirContext;
|
32
|
31
|
|
33
|
32
|
/**
|
34
|
33
|
* Class to represent an SRV Record.
|
|
@@ -61,7 +60,7 @@ public class SRVRecord implements Comparable<SRVRecord> {
|
61
|
60
|
priority = Integer.parseInt(bits[0]);
|
62
|
61
|
weight = Integer.parseInt(bits[1]);
|
63
|
62
|
port = Integer.parseInt(bits[2]);
|
64
|
|
- host = (bits[3].charAt(bits[3].length() - 1) == '.') ? bits[3].substring(0, bits[3].length() - 1) : bits[3];
|
|
63
|
+ host = bits[3].charAt(bits[3].length() - 1) == '.' ? bits[3].substring(0, bits[3].length() - 1) : bits[3];
|
65
|
64
|
} catch (final NumberFormatException nfe) {
|
66
|
65
|
throw new NamingException("Unable to parse SRV Record parameters."); // NOPMD
|
67
|
66
|
}
|
|
@@ -105,25 +104,23 @@ public class SRVRecord implements Comparable<SRVRecord> {
|
105
|
104
|
|
106
|
105
|
@Override
|
107
|
106
|
public String toString() {
|
108
|
|
- return priority + " " + weight + " " + port + " " + host + ".";
|
|
107
|
+ return priority + " " + weight + ' ' + port + ' ' + host + '.';
|
109
|
108
|
}
|
110
|
109
|
|
111
|
110
|
@Override
|
112
|
111
|
public int compareTo(final SRVRecord o) {
|
113
|
|
- if (this.priority < o.priority) { return -1; }
|
114
|
|
- if (this.priority > o.priority) { return 1; }
|
|
112
|
+ if (priority < o.getPriority()) { return -1; }
|
|
113
|
+ if (priority > o.getPriority()) { return 1; }
|
115
|
114
|
return 0;
|
116
|
115
|
}
|
117
|
116
|
|
118
|
117
|
public static List<SRVRecord> getRecords(final String host) {
|
119
|
118
|
final List<SRVRecord> result = new ArrayList<>();
|
120
|
|
-
|
121
|
|
- try {
|
122
|
|
- // Obsolete Collection. yeah yeah...
|
123
|
|
- final Hashtable<String, String> env = new Hashtable<>(); // NOPMD - Required by InitialDirContext
|
124
|
|
- env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
|
125
|
|
- env.put("java.naming.provider.url", "dns:");
|
126
|
|
- final Attribute attr = new InitialDirContext(env).getAttributes(host, new String [] { "SRV" }).get("SRV");
|
|
119
|
+ final HashMap<String, String> env = new HashMap<>();
|
|
120
|
+ env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
|
|
121
|
+ env.put("java.naming.provider.url", "dns:");
|
|
122
|
+ try (AutoCloseableInitialDirContext dirContext = new AutoCloseableInitialDirContext(env)) {
|
|
123
|
+ final Attribute attr = dirContext.getAttributes(host, new String [] { "SRV" }).get("SRV");
|
127
|
124
|
|
128
|
125
|
if (attr != null) {
|
129
|
126
|
final NamingEnumeration<?> ne = attr.getAll();
|