Java URI Value Check isValidURIorEmpty(String uri)

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

Description

Check if the given input string is a valid URI

License

LGPL

Parameter

Parameter Description
uri a parameter

Declaration

public static boolean isValidURIorEmpty(String uri) 

Method Source Code

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

import java.net.URI;

public class Main {
    /**//from w  ww . j av  a  2s.  c o  m
     * Check if the given input string is a valid URI
     * @param uri
     * @return
     */
    public static boolean isValidURIorEmpty(String uri) {

        if (uri == null || uri.trim().isEmpty()) {
            return true;
        }

        try {
            URI.create(uri);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}

Related

  1. isValidURI(final String namespace)
  2. isValidURI(String uri)
  3. isValidUri(String uri, StringBuilder errMsg)
  4. isValidUri(String uriCandidate)
  5. isValidURI(String uriRef)
  6. isValidURIReference(String uriRef)
  7. isVirtual(URI locationURI)
  8. isVSO(final URI uri)
  9. isWellFormedUriString(final String uriString)