Java Utililty Methods URI Value Check

List of utility methods to do URI Value Check

Description

The list of methods to do URI Value Check are organized into topic(s).

Method

booleanisValidURI(String uriRef)
is Valid URI
boolean isValid = !uriRef.matches("[\u0000-\u001F\u007F-\u009F]");
try {
    final java.net.URI uri = new java.net.URI(uriRef);
    isValid = uri.isAbsolute();
} catch (URISyntaxException e) {
    isValid = false;
return isValid;
...
booleanisValidURIorEmpty(String uri)
Check if the given input string is a valid URI
if (uri == null || uri.trim().isEmpty()) {
    return true;
try {
    URI.create(uri);
    return true;
} catch (Exception e) {
    return false;
...
booleanisValidURIReference(String uriRef)
Verifies that the supplied string is a valid RDF (1.0) URI reference, as defined in section 6.4 of the RDF Concepts and Abstract Syntax specification (RDF 1.0 Recommendation of February 10, 2004).
boolean valid = !uriRef.matches("[\u0000-\u001F\u007F-\u009F]");
if (valid) {
    final String escaped = escapeExcludedChars(uriRef);
    try {
        final java.net.URI uri = new java.net.URI(escaped);
        valid = uri.isAbsolute();
    } catch (URISyntaxException e) {
        valid = false;
...
booleanisVirtual(URI locationURI)
see issue 12500: we should check whether the resource is virtual

TODO as soon as 3.5 is not supported, use resource.isVirtual() call

return locationURI == null || "virtual".equals(locationURI.getScheme());
booleanisVSO(final URI uri)
is VSO
final String host = uri.getHost().toLowerCase();
if (host.endsWith(HOST_VSO) || host.endsWith(HOST_TFS_ALL_IN)) {
    return true;
} else {
    return false;
booleanisWellFormedUriString(final String uriString)
is Well Formed Uri String
try {
    new URI(uriString);
    return true;
} catch (final URISyntaxException ignored) {
    return false;
URIvalidateURI(final String uri)
Just test to see if the given string can be parse into a URI.
try {
    return new URI(uri);
} catch (final Exception mfue) {
return null;
voidvalidateUri(String uri)
validate Uri
try {
    new URI(uri);
} catch (Exception e) {
    throw new Error(e);
StringvalidateURI(String uri)
Verifies the validity of a complete URI
try {
    new URI(uri);
} catch (URISyntaxException e) {
    throw e;
return uri;
StringvalidateUri(String uri)
validate Uri
final URL url;
try {
    url = new URL(uri);
} catch (Exception e1) {
    return ("'" + uri + "' is not a valid URL: " + e1.getLocalizedMessage());
if (!"http".equals(url.getProtocol())) {
    return ("'" + uri + "' is not a valid URL: Model name must use http protocol.");
...