Java URI Value Check isLocalFile(URI uri)

Here you can find the source of isLocalFile(URI uri)

Description

Checks if the URI points to the local file.

License

Creative Commons License

Parameter

Parameter Description
uri the uri to check

Return

true if the URI points to a local file

Declaration

public static boolean isLocalFile(URI uri) 

Method Source Code

//package com.java2s;
/*/*w w w .  j a va2  s .  c om*/
 * Written by Dawid Kurzyniec and released to the public domain, as explained
 * at http://creativecommons.org/licenses/publicdomain
 */

import java.net.*;

public class Main {
    /**
     * Checks if the URI points to the local file.
     * @param uri the uri to check
     * @return true if the URI points to a local file
     */
    public static boolean isLocalFile(URI uri) {
        if (!uri.isAbsolute())
            return false;
        if (uri.isOpaque())
            return false;
        if (!"file".equalsIgnoreCase(uri.getScheme()))
            return false;
        if (uri.getAuthority() != null)
            return false;
        if (uri.getFragment() != null)
            return false;
        if (uri.getQuery() != null)
            return false;
        if ("".equals(uri.getPath()))
            return false;
        return true;
    }

    public static boolean isAbsolute(String path) {
        return (path.length() > 0 && path.charAt(0) == '/');
    }
}

Related

  1. isJar(final URI uri)
  2. isJarFile(final URI uri)
  3. isLocal(final URI uri)
  4. isLocal(final URI uri)
  5. isLocalFile(URI uri)
  6. isLocalUri(String uriString)
  7. isLocalURI(URI uri)
  8. isModuleURI(URI uri)
  9. isNormalized(String uriName)