mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Add timeout to reading URL from website
This commit is contained in:
@@ -25,6 +25,7 @@ import java.net.URL;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -248,17 +249,18 @@ public final class FileUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> readFile(final URL url) {
|
public static List<String> readFile(final URL url) {
|
||||||
List<String> lines = new ArrayList<String>();
|
final List<String> lines = new ArrayList<String>();
|
||||||
try {
|
ThreadUtil.executeWithTimeout(new Callable<Void>() {
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
|
@Override
|
||||||
String line;
|
public Void call() throws Exception {
|
||||||
while ((line = in.readLine()) != null) {
|
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||||
lines.add(line);
|
String line;
|
||||||
|
while ((line = in.readLine()) != null) {
|
||||||
|
lines.add(line);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}, 5000); //abort reading file if it takes longer than 5 seconds
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user