aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/measite/minidns
diff options
context:
space:
mode:
authorFlorian Schmaus <flo@geekplace.eu>2014-06-08 13:33:14 +0200
committerFlorian Schmaus <flo@geekplace.eu>2014-06-08 13:33:14 +0200
commitdefe51910153ed6a9aaf6becae9e6484bed609bd (patch)
tree0a81efb5b3acbf5853427b14117b42bcd2a929ea /src/main/java/de/measite/minidns
parent3236432c39f1d5a1bbbe362c5cfdb088756fd04f (diff)
Close DatagramSocket using try-with-resources
Diffstat (limited to 'src/main/java/de/measite/minidns')
-rw-r--r--src/main/java/de/measite/minidns/Client.java23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/main/java/de/measite/minidns/Client.java b/src/main/java/de/measite/minidns/Client.java
index fb42cd25..e20c007e 100644
--- a/src/main/java/de/measite/minidns/Client.java
+++ b/src/main/java/de/measite/minidns/Client.java
@@ -131,18 +131,19 @@ public class Client {
message.setRecursionDesired(true);
message.setId(random.nextInt());
byte[] buf = message.toArray();
- DatagramSocket socket = new DatagramSocket();
- DatagramPacket packet = new DatagramPacket(
- buf, buf.length, InetAddress.getByName(host), port);
- socket.setSoTimeout(timeout);
- socket.send(packet);
- packet = new DatagramPacket(new byte[bufferSize], bufferSize);
- socket.receive(packet);
- DNSMessage dnsMessage = DNSMessage.parse(packet.getData());
- if (dnsMessage.getId() != message.getId()) {
- return null;
+ try (DatagramSocket socket = new DatagramSocket()) {
+ DatagramPacket packet = new DatagramPacket(buf, buf.length,
+ InetAddress.getByName(host), port);
+ socket.setSoTimeout(timeout);
+ socket.send(packet);
+ packet = new DatagramPacket(new byte[bufferSize], bufferSize);
+ socket.receive(packet);
+ DNSMessage dnsMessage = DNSMessage.parse(packet.getData());
+ if (dnsMessage.getId() != message.getId()) {
+ return null;
+ }
+ return dnsMessage;
}
- return dnsMessage;
}
/**