Java Utililty Methods URL Value Check

List of utility methods to do URL Value Check

Description

The list of methods to do URL Value Check are organized into topic(s).

Method

booleanisURL(String token)
Returns true if the input token is a URL, and false otherwise.
try {
    URL url = new URL(token);
    return true;
} catch (MalformedURLException e) {
    return false;
booleanisUrl(String value)
is Url
try {
    new java.net.URL(value);
} catch (MalformedURLException e) {
    return false;
return true;
booleanisURLAccessible(String URL)
Finds out whether a URL returns HTTP OK or not.
try {
    HttpURLConnection.setFollowRedirects(false);
    HttpURLConnection connection = (HttpURLConnection) new URL(URL).openConnection();
    connection.setRequestMethod("HEAD");
    return (connection.getResponseCode() == HttpURLConnection.HTTP_OK);
} catch (Exception e) {
    return false;
booleanisURLAvailable(String url, int timeout)
is URL Available
try {
    return isURLAvailable(new URL(url), timeout);
} catch (MalformedURLException e) {
    e.printStackTrace();
    return false;
booleanisUrlAvailable(URL url, Proxy proxy)
Checks whether the specified URL points to a valid resource.
if (url != null) {
    if (url.getProtocol().equalsIgnoreCase("http") || url.getProtocol().equalsIgnoreCase("https")) {
        HttpURLConnection.setFollowRedirects(true);
        HttpURLConnection conn = null;
        if (proxy != null) {
            conn = (HttpURLConnection) url.openConnection(proxy);
        } else {
            conn = (HttpURLConnection) url.openConnection();
...
booleanisUrlDownWithRetries(String url, long timeoutMs, long retryDelayMs)
Returns true if the URL status code is not 200.
return getUrlContentWithRetries(url, timeoutMs, retryDelayMs, true) == null;
booleanisUrlExists(String url)
is Url Exists
try {
    URL urlObject = new URL(url);
    HttpURLConnection huc = (HttpURLConnection) urlObject.openConnection();
    huc.setRequestMethod("HEAD");
    huc.connect();
    return huc.getResponseCode() == 200;
} catch (IOException ignored) {
return false;
booleanisURLExists(String URLName)
is URL Exists
try {
    if (!URLName.toUpperCase().contains("HTTP"))
        URLName = "http://" + URLName;
    URL url = new URL(URLName);
    System.setProperty("java.net.useSystemProxies", "true");
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    urlConn.setConnectTimeout(9000);
    urlConn.setReadTimeout(9000);
...
booleanisUrlInJar(URL url)
is Url In Jar
return url == null ? false : url.toString().startsWith("jar:");
booleanisUrlResponding(String url)
is Url Responding
try {
    return isUrlResponding(new URL(url));
} catch (MalformedURLException e) {
return false;