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

@@ -194,8 +194,8 @@ public class HTTPMUSocket
public boolean send(String msg, String bindAddr, int bindPort)
{
MulticastSocket msock = null;
try {
MulticastSocket msock;
if ((bindAddr) != null && (0 < bindPort)) {
msock = new MulticastSocket(null);
msock.bind(new InetSocketAddress(bindAddr, bindPort));
@@ -206,11 +206,12 @@ public class HTTPMUSocket
// Thnaks for Theo Beisch (11/09/04)
msock.setTimeToLive(UPnP.getTimeToLive());
msock.send(dgmPacket);
msock.close();
}
catch (Exception e) {
Debug.warning(e);
return false;
} finally {
if (msock != null) msock.close();
}
return true;
}