Skip to content

Commit

Permalink
#296: fix isOnline check (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
slskiba authored Jun 12, 2024
1 parent 4fac5c5 commit e061084
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
Expand Down Expand Up @@ -598,7 +599,13 @@ public boolean isOnline() {
boolean online = false;
try {
int timeout = 1000;
online = InetAddress.getByName("github.com").isReachable(timeout);
//open a connection to github.com and try to retrieve data
//getContent fails if there is no connection
URLConnection connection = new URL("https://www.github.com").openConnection();
connection.setConnectTimeout(timeout);
connection.getContent();
online = true;

} catch (Exception ignored) {

}
Expand Down

0 comments on commit e061084

Please sign in to comment.