/**
 * 
 */
package eu.dnetlib.miscutils.url;

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

/**
 * The Class UrlUtils.
 * 
 * @author <a href="mailto:marek.imialek at uni-bielefeld.de">Marek Imialek</a>
 */
public class UrlUtils {

	/**
	 * Function checks if the specified url is available.
	 * 
	 * @param URLName the uRL name
	 * 
	 * @return true, if successful
	 */
	public static boolean exists(String url){
	    try {
	      HttpURLConnection.setFollowRedirects(false);
	      HttpURLConnection connnection =
	         (HttpURLConnection) new URL(url).openConnection();
	      connnection.setRequestMethod("HEAD");
	      return (connnection.getResponseCode() == HttpURLConnection.HTTP_OK);
	    }
	    catch (Exception e) {
	       e.printStackTrace();
	       return false;
	    }
	  }
}
