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

booleanisUrlValid(final URL url)
Quickly checks to see whether URL is reachable.
final int timeout = 2000; 
if (url == null)
    return false;
try {
    final HttpURLConnection huc = (HttpURLConnection) url.openConnection();
    huc.setRequestMethod("HEAD");
    huc.setConnectTimeout(timeout); 
    final int responseCode = huc.getResponseCode();
...
booleanisUrlValid(URL url)
is Url Valid
try {
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("HEAD");
    int responseCode = connection.getResponseCode();
    return (responseCode == 200);
} catch (IOException e) {
    e.printStackTrace();
return false;
booleanisValid(String candidateUrl)
Check if a given string is a valid url format.
try {
    URL url = new URL(candidateUrl);
    return true;
} catch (MalformedURLException e) {
    return false;
booleanisValid(String url)
is Valid
if (SIMPLE_URL_PATTERN.matcher(url).matches()) {
    try {
        new URI(url);
        new URL(url);
    } catch (MalformedURLException | URISyntaxException e) {
        return false;
    return true;
...
booleanisValidChannelUrl(String url)
is Valid Channel Url
try {
    URI uri = new URI(url);
    return uri.getPath().contains("/channel/");
} catch (URISyntaxException e) {
    return false;
booleanisValidServerURL(String serverURL)
is Valid Server URL
try {
    HttpURLConnection.setFollowRedirects(false);
    URL url = new URL(serverURL);
    int port = url.getPort();
    if (port == -1) {
        port = (url.getProtocol().equalsIgnoreCase("http") ? 80 : 443);
    Socket socket = new Socket(url.getHost(), port);
...
booleanisValidSuccessfulSignInURL(String url)
is Valid Successful Sign In URL
try {
    URL urlObj = new URL(url);
    if (!urlObj.getProtocol().equals("https")) {
        return false;
    if (!urlObj.getAuthority().equals("www.facebook.com")) {
        return false;
    if (!urlObj.getHost().equals("www.facebook.com")) {
        return false;
    if (!urlObj.getPath().equals("/connect/login_success.html")) {
        return false;
    String ref = urlObj.getRef();
    if (ref == null) {
        return false;
    if (!ref.contains("access_token=")) {
        return false;
    return ref.contains("expires_in=");
} catch (MalformedURLException e) {
return false;
booleanisValidURL(CharSequence urlStr)
Determines if the passed string is a valid URL
if (urlStr == null)
    return false;
try {
    new URL(urlStr.toString());
    return true;
} catch (Exception e) {
    return false;
booleanisValidURL(final String candidateString)

Checks that the specified string meets the requirements of the URL specification.

boolean result;
try {
    new URL(candidateString);
    result = true;
} catch (Throwable throwable) {
    result = false;
return result;
...
booleanisValidURL(String link)
Checks a url is in a valid form or not.
try {
    if ((link == null) || (link.length() == 0))
        return false;
    if (link.indexOf('.') == -1)
        return false;
    if (!URL_PATTERN.matcher(link).matches())
        return false;
    if (hasValidDomain(link))
...