Java URI Value Check isUriValid(String uri)

Here you can find the source of isUriValid(String uri)

Description

is Uri Valid

License

Apache License

Declaration

public static boolean isUriValid(String uri) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.HttpURLConnection;

import java.net.URL;

public class Main {
    public static boolean isUriValid(String uri) {
        uri = uri.trim();//from w  ww  . j ava 2 s  . c  o m

        if (responseCodeOfURI(uri) == 200)
            return true;
        return false;
    }

    public static int responseCodeOfURI(String uri) {
        HttpURLConnection connection = null;
        try {
            URL url = new URL(uri);
            connection = (HttpURLConnection) url.openConnection();

            connection.setRequestMethod("HEAD");
            int code = connection.getResponseCode();
            return code;
        } catch (Exception ex) {
            return -1;
        }

    }
}

Related

  1. isType(URI uri, Class clazz)
  2. isType(URI uri, String name)
  3. isURI(Class type)
  4. isURI(String plainString)
  5. isURI(String uri)
  6. isUsingNonDefaultPort(URI uri)
  7. isValid(String uri)
  8. isValid(URI uri)
  9. isValidURI(final String namespace)