mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-10-04 09:27:27 +02:00
More socket leak prevention measures just in case
This commit is contained in:
parent
1159f67f28
commit
bc7e84677f
@ -20,6 +20,7 @@ import javax.inject.Inject;
|
|||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@ -75,12 +76,16 @@ public class IP2CGeolocator implements Geolocator {
|
|||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
try {
|
try {
|
||||||
connection = (HttpURLConnection) new URL("http://ip2c.org/" + address).openConnection();
|
connection = (HttpURLConnection) new URL("http://ip2c.org/" + address).openConnection();
|
||||||
|
connection.setConnectTimeout((int) TimeUnit.MINUTES.toMillis(1L));
|
||||||
|
connection.setReadTimeout((int) TimeUnit.MINUTES.toMillis(1L));
|
||||||
connection.setUseCaches(false);
|
connection.setUseCaches(false);
|
||||||
connection.connect();
|
connection.connect();
|
||||||
try (
|
try (
|
||||||
InputStream in = connection.getInputStream()
|
InputStream in = connection.getInputStream();
|
||||||
|
OutputStream out = connection.getOutputStream()
|
||||||
) {
|
) {
|
||||||
String answer = readAnswer(in);
|
String answer = readAnswer(in);
|
||||||
|
out.close();
|
||||||
return resolveIP(answer);
|
return resolveIP(answer);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
Loading…
Reference in New Issue
Block a user