23 package com.realtime.crossfire.jxclient.metaserver;
25 import java.io.BufferedReader;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.io.InputStreamReader;
29 import java.net.HttpURLConnection;
31 import java.nio.charset.StandardCharsets;
32 import java.util.ArrayList;
33 import java.util.Collection;
34 import org.jetbrains.annotations.NotNull;
61 assert localhostMetaserverEntry !=
null;
62 final Collection<MetaserverEntry> result =
new ArrayList<>();
63 result.add(localhostMetaserverEntry);
66 final String httpProxy = System.getenv(
"http_proxy");
67 if (httpProxy !=
null && !httpProxy.isEmpty()) {
68 if (httpProxy.regionMatches(
true, 0,
"http://", 0, 7)) {
69 final String[] tmp = httpProxy.substring(7).replaceAll(
"/.*",
"").split(
":", 2);
70 System.setProperty(
"http.proxyHost", tmp[0]);
71 System.setProperty(
"http.proxyPort", tmp.length >= 2 ? tmp[1] :
"80");
73 System.err.println(
"Warning: unsupported http_proxy protocol: "+httpProxy);
77 final HttpURLConnection conn = (HttpURLConnection)url.openConnection();
79 conn.setRequestMethod(
"GET");
80 conn.setUseCaches(
false);
82 if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
83 final InputStream in = conn.getInputStream();
84 try (InputStreamReader isr =
new InputStreamReader(in, StandardCharsets.ISO_8859_1)) {
85 try (BufferedReader br =
new BufferedReader(isr)) {
88 final String line = br.readLine();
94 if (metaserverEntry !=
null) {
95 result.add(metaserverEntry);
104 }
catch (
final IOException ignored) {