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

booleancheckUrl(final String link)
check Url
try {
    URL url = new URL(link);
    URLConnection conn = url.openConnection();
    conn.connect();
    return true;
} catch (Exception e) {
return false;
...
intcheckURL(String _url)
check URL
int ans = 0;
int dots = (numberOfDots(_url)); 
if (dots >= 3)
    ans += dots * 5;
ans += suspiciousURL(_url) * 2;
if (hasIP(_url)) {
    ans += 80;
if (hasEmbeddedDomain(_url))
    ans += 80;
if (outOfPositionTLD(_url))
    ans += 40;
ans += senstiveWords(_url) * 10;
return ans;
booleancheckUrl(String inputUrlString)
check Url
URL url = new URL(inputUrlString);
return checkUrl(url);
intcheckUrl(String url, int timeout)
check Url
try {
    URL url2 = null;
    HttpURLConnection conn = null;
    url2 = new URL(url);
    conn = (HttpURLConnection) url2.openConnection();
    long len = conn.getContentLength();
    conn.setConnectTimeout(timeout);
    return conn.getResponseCode();
...
URLcheckURL(URL check)
check URL
URL result = null;
if (check != null) {
    try {
        InputStream is = check.openStream();
        is.close();
        result = check;
    } catch (IOException e) {
return result;
voidcheckUrl(URL url, URL baseUrl)
check Url
if (baseUrl.getHost() == null) {
    throw new RuntimeException("base URL is null");
if (!baseUrl.getHost().equalsIgnoreCase(url.getHost())) {
    throw new RuntimeException("Domain of URL " + url + " doesn't match base URL " + baseUrl);
StringcheckURLAvailable(String targetUrl)
check URL Available
try {
    URL url = new URL(targetUrl);
    URLConnection urlConnection = url.openConnection();
    HttpURLConnection.setFollowRedirects(true);
    HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
    httpURLConnection.setRequestMethod("HEAD");
    if (httpURLConnection.getResponseCode() >= MIN_HTTP_VALID_CODE
            && httpURLConnection.getResponseCode() < MAX_HTTP_VALID_CODE) {
...
booleancheckUrlImage(final String url)
Blocking.
try {
    final HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
    return connection.getResponseCode() == 200 && connection.getContentType() != null
            && connection.getContentType().contains("image");
} catch (Exception e) {
    return false;
booleancheckURLStatus(String pURL)
check URL Status
URL url = null;
HttpURLConnection conn = null;
try {
    url = new URL(pURL);
    conn = (HttpURLConnection) url.openConnection();
    conn.connect();
    return true;
} catch (MalformedURLException e) {
...
booleancheckURLValidProtocol(URL url)
Returns true if the supplied URL is using one of the formats supported by open-delta - the supported formats are http, ftp and file.
return (url.getProtocol().equalsIgnoreCase("http")
        || (url.getProtocol().equalsIgnoreCase("ftp") || (url.getProtocol().equalsIgnoreCase("file"))));