Java URL Value Check isHttpUrl(final URI toCheck)

Here you can find the source of isHttpUrl(final URI toCheck)

Description

Determine if a URL is a URL using HTTP or HTTPS protocols

License

Apache License

Parameter

Parameter Description
toCheck The URI to check

Return

true if the URI is a URL with a non-empty host and uses either the http or https protocol

Declaration

public static boolean isHttpUrl(final URI toCheck) 

Method Source Code

//package com.java2s;
/*/*from  w  w  w.ja  va2  s.  c  om*/
 * Copyright 2016 Johns Hopkins University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.net.URI;
import java.net.URISyntaxException;

public class Main {
    /**
     * Determine if a URL is a URL using HTTP or HTTPS protocols
     *
     * @param toCheck The URI to check
     * @return true if the URI is a URL with a non-empty host and uses either the http or https protocol
     */
    public static boolean isHttpUrl(final URI toCheck) {
        return toCheck.getHost() != null
                && (toCheck.getScheme().equals("http") || toCheck.getScheme().equals("https"));
    }

    /**
     * Determine if a string is a URL with HTTP or HTTPS protocols
     *
     * @param toCheck the string to check
     * @return true if the string is a URL with http or https protocols
     */
    public static boolean isHttpUrl(final String toCheck) {
        try {
            return isHttpUrl(new URI(toCheck));
        } catch (final URISyntaxException e) {
            return false;
        }
    }
}

Related

  1. isFileURL(URL url)
  2. isFileURL(URL url)
  3. isHosting(URL url_in)
  4. isHTTP(URL url)
  5. isHttpOk(String url)
  6. isHttpUrl(final URL url)
  7. isHttpUrl(String in)
  8. isHttpUrl(URL url)
  9. isHttpUrl(URL url)