Cleanups: Close resources via try-finally

We can't use try-with-resources until we bump the minimum-supported Android
version for the client library to API 19.
This commit is contained in:
str4d
2017-12-09 01:02:17 +00:00
parent fe5e4a2c7a
commit a67ea4b2f2
14 changed files with 81 additions and 46 deletions

View File

@@ -243,10 +243,11 @@ public class SAMStreamSink {
}
public void run() {
DatagramSocket dg = null;
byte[] buf = new byte[32768];
try {
Sink sink = new Sink("FAKE", "FAKEFROM");
DatagramSocket dg = new DatagramSocket(V3DGPORT);
dg = new DatagramSocket(V3DGPORT);
while (true) {
DatagramPacket p = new DatagramPacket(buf, 32768);
dg.receive(p);
@@ -283,6 +284,8 @@ public class SAMStreamSink {
}
} catch (IOException ioe) {
_log.error("DGRcvr", ioe);
} finally {
if (dg != null) dg.close();
}
}
}