Java URL Connection isUrlReachable(String url)

Here you can find the source of isUrlReachable(String url)

Description

is Url Reachable

License

Open Source License

Declaration

public static boolean isUrlReachable(String url) 

Method Source Code

//package com.java2s;
/*//  w  ww . java 2s.com
 * Copyright (c) Bosch Software Innovations GmbH 2016.
 * With modifications by Siemens AG, 2016.
 * Part of the SW360 Portal Project.
 *
 * SPDX-License-Identifier: EPL-1.0
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;

public class Main {
    private static final int CONNECT_TIMEOUT = 10000;

    public static boolean isUrlReachable(String url) {
        try {
            final URLConnection connection = new URL(url).openConnection();
            connection.setConnectTimeout(CONNECT_TIMEOUT);
            connection.connect();
            return true;
        } catch (final IOException e) {
            return false;
        }
    }
}

Related

  1. getWebsiteContents(URL url)
  2. httpPost(String urlString, String postPath, Map keyValuePairs)
  3. imageFromUrl(String url)
  4. isJarDirectory(JarURLConnection conn)
  5. isOnline(String url)
  6. isValidToc(URL url)
  7. isValidUrl(String input)
  8. isZipName(URI documentIRI, URLConnection connection)
  9. jarURLDirectories(URL jarURL)