You can write your own simple method to try both protocols, like:
static boolean usesHttps(final String urlWithoutProtocol) throws IOException {
try {
Jsoup.connect("http://" + urlWithoutProtocol).get();
return false;
} catch (final IOException e) {
Jsoup.connect("https://" + urlWithoutProtocol).get();
return true;
}
}
Then, your original code can be:
try {
boolean shouldUseHttps = usesHttps("google.com");
} catch (final IOException ex) {
Logger.getLogger(LinkGUI.class.getName()).log(Level.SEVERE, null, ex);
}
Note: you should only use the usesHttps() method once per URL, to figure out which protocol to use. After you know that, you should connect using Jsoup.connect() directly. This will be more efficient.