Skip to content

Commit 812cd66

Browse files
committed
Add timeout to skull texture fetching
1 parent d5b24cc commit 812cd66

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/java/eu/decentsoftware/holograms/api/utils/items/SkullUtils.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import java.io.InputStreamReader;
2020
import java.lang.reflect.Field;
2121
import java.lang.reflect.Method;
22+
import java.net.HttpURLConnection;
2223
import java.net.URL;
24+
import java.net.URLConnection;
2325
import java.util.Collection;
2426
import java.util.UUID;
2527

@@ -235,9 +237,12 @@ public static String getPlayerUUID(String playerName) {
235237
@NonNull
236238
private static String readUrl(String urlString) throws Exception {
237239
BufferedReader reader = null;
240+
URLConnection connection = null;
238241
try {
239-
URL url = new URL(urlString);
240-
reader = new BufferedReader(new InputStreamReader(url.openStream()));
242+
connection = new URL(urlString).openConnection();
243+
connection.setConnectTimeout(50);
244+
connection.setReadTimeout(50);
245+
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
241246
StringBuilder builder = new StringBuilder();
242247
int read;
243248
char[] chars = new char[1024];
@@ -246,6 +251,9 @@ private static String readUrl(String urlString) throws Exception {
246251
}
247252
return builder.toString();
248253
} finally {
254+
if (connection instanceof HttpURLConnection) {
255+
((HttpURLConnection) connection).disconnect();
256+
}
249257
if (reader != null) {
250258
reader.close();
251259
}

0 commit comments

Comments
 (0)