Java URL Value Check checkUrlImage(final String url)

Here you can find the source of checkUrlImage(final String url)

Description

Blocking.

License

Open Source License

Declaration

public static boolean checkUrlImage(final String url) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    /** Blocking. Ensures the specified URL corresponds to an image. */
    public static boolean checkUrlImage(final String url) {
        try {//from   w  ww . jav a 2 s.co  m
            final HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();

            return connection.getResponseCode() == 200 && connection.getContentType() != null
                    && connection.getContentType().contains("image");
        } catch (Exception e) {
            return false;
        }
    }
}

Related

  1. checkUrl(String inputUrlString)
  2. checkUrl(String url, int timeout)
  3. checkURL(URL check)
  4. checkUrl(URL url, URL baseUrl)
  5. checkURLAvailable(String targetUrl)
  6. checkURLStatus(String pURL)
  7. checkURLValidProtocol(URL url)
  8. invokePostUrl(String url, String encodedQueryString)
  9. invokeUrl(String url)