Example usage for java.net URI equals

List of usage examples for java.net URI equals

Introduction

In this page you can find the example usage for java.net URI equals.

Prototype

public boolean equals(Object ob) 

Source Link

Document

Tests this URI for equality with another object.

Usage

From source file:Main.java

public static void main(String[] args) throws NullPointerException, URISyntaxException {
    URI uri = new URI("http://www.java2s.com:8080/yourpath/fileName.htm");
    URI uri1 = new URI("http://www.java2s.com:8080/yourpath/fileName.htm");
    System.out.println(uri.equals(uri1));
}

From source file:es.mityc.firmaJava.libreria.xades.elementos.EncodingEnum.java

public static EncodingEnum getEncoding(String uri) {
    try {// w ww  .j av  a2 s .  com
        URI temp = new URI(uri);
        if (temp.equals(DER_ENCODED.uri))
            return DER_ENCODED;
        else if (temp.equals(BER_ENCODED.uri))
            return BER_ENCODED;
        else if (temp.equals(CER_ENCODED.uri))
            return CER_ENCODED;
        else if (temp.equals(PER_ENCODED.uri))
            return PER_ENCODED;
        else if (temp.equals(XER_ENCODED.uri))
            return XER_ENCODED;
    } catch (URISyntaxException ex) {
        if (logger.isDebugEnabled())
            logger.debug("Encoding indicado no es una URI", ex);
        return null;
    }
    return null;
}

From source file:org.eclipse.aether.transport.http.UriUtils.java

private static boolean isBase(URI base, URI uri) {
    String path = uri.getRawPath();
    if (path == null || "/".equals(path)) {
        return true;
    }/*w ww.j  a va  2  s. c  om*/
    if (base != null) {
        URI rel = base.relativize(uri);
        if (rel.getRawPath() == null || rel.getRawPath().length() <= 0 || rel.equals(uri)) {
            return true;
        }
    }
    return false;
}

From source file:ee.ria.xroad.proxy.clientproxy.FastestConnectionSelectingSSLSocketFactory.java

private static boolean isSessionHost(SSLSession session, URI host) {
    try {//from   w w  w  .ja  va  2s .  co m
        URI sslHost = (URI) session.getValue(ID_SELECTED_TARGET);
        return sslHost != null && sslHost.equals(host);
    } catch (Exception e) {
        log.error("Error checking if host {} is in session ({}).", host, session);
        log.error("Exception :{}", e);
    }

    return false;
}

From source file:org.apache.hadoop.hdfs.server.namenode.AvatarStorageSetup.java

/**
 * Shared image needs to be in file storage, or QJM providing that QJM also
 * stores edits.//  ww  w . j  a va  2s.co  m
 */
private static String checkImageStorage(URI sharedImage, URI sharedEdits) {
    if (sharedImage.getScheme().equals(NNStorage.LOCAL_URI_SCHEME)) {
        // shared image is stored in file storage
        return "";
    } else if (sharedImage.getScheme().equals(QuorumJournalManager.QJM_URI_SCHEME)
            && sharedImage.equals(sharedEdits)) {
        // image is stored in qjm together with edits
        return "";
    }
    return "Shared image uri: " + sharedImage + " must be either file storage"
            + " or be equal to shared edits storage " + sharedEdits + ". ";
}

From source file:org.apache.hadoop.hdfs.server.namenode.ValidateNamespaceDirPolicy.java

private static NNStorageLocation checkLocation(URI location, Configuration conf, URI sharedLocation)
        throws IOException {

    // check shared locations (for file and non-file locations
    boolean isShared = false;
    if (sharedLocation != null) {
        // check if the location is shared     
        isShared = location.equals(sharedLocation);
    }//from www  .  j  av a  2 s .  c  o  m

    // handle non-file locations
    if ((location.getScheme().compareTo(JournalType.FILE.name().toLowerCase()) != 0)) {
        // non-file locations are all remote - we might want to add more checks in the future
        // mount point is set to the uri scheme
        return new NNStorageLocation(location, location.getScheme().toLowerCase(),
                isShared ? StorageLocationType.SHARED : StorageLocationType.REMOTE);
    } else {
        // enforce existence
        checkDirectory(location.getPath());

        try {
            return getInfoUnix(location, isShared);
        } catch (Exception e) {
            FLOG.info("Failed to fetch information with unix based df", e);
        }
        try {
            return getInfoMacOS(location, isShared);
        } catch (Exception e) {
            FLOG.info("Failed to fetch information with macos based df", e);
        }
        throw new IOException("Failed to run df");
    }
}

From source file:com.alexholmes.hdfsslurper.Configurator.java

public static boolean compareFs(FileSystem fs1, FileSystem fs2) {
    URI uri1 = fs1.getUri();
    URI uri2 = fs2.getUri();/*from  w  ww . j a  v a  2  s  . co  m*/
    if (uri1.getScheme() == null) {
        return false;
    }
    if (!uri1.getScheme().equals(uri2.getScheme())) {
        return false;
    }
    return uri1.equals(uri2);
}

From source file:com.vmware.identity.openidconnect.protocol.URIUtils.java

public static boolean areEqual(URI lhs, URI rhs) {
    Validate.notNull(lhs, "lhs");
    Validate.notNull(rhs, "rhs");

    URI lhsCopy;
    URI rhsCopy;/*from   www.ja  va  2 s . c  o  m*/
    try {
        lhsCopy = new URI(lhs.getScheme(), lhs.getUserInfo(), lhs.getHost(), URIUtils.getPort(lhs),
                lhs.getPath(), lhs.getQuery(), lhs.getFragment());
        rhsCopy = new URI(rhs.getScheme(), rhs.getUserInfo(), rhs.getHost(), URIUtils.getPort(rhs),
                rhs.getPath(), rhs.getQuery(), rhs.getFragment());
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("failed to transform uri for equality check", e);
    }

    return lhsCopy.equals(rhsCopy);
}

From source file:org.objectweb.proactive.core.remoteobject.RemoteObjectSet.java

/**
 * Helper method used to sort the list of protocols
 * @param input//from  w  ww.  j  ava 2  s .c  o m
 * @param defOrder
 * @param benchmarkRes
 * @param defUri
 * @return
 */
public static ArrayList<URI> sortProtocols(Collection<URI> input, final List<String> defOrder,
        final ConcurrentHashMap<URI, Integer> benchmarkRes, final URI defUri) {

    ArrayList<URI> output = new ArrayList<URI>();
    output.addAll(input);

    Collections.sort(output, new Comparator<URI>() {
        @Override
        public int compare(URI o1, URI o2) {

            // unreachable uri, they are put at the end of the list
            if (benchmarkRes.containsKey(o1) && benchmarkRes.get(o1) == UNREACHABLE_VALUE) {
                return 1;
            }
            if (benchmarkRes.containsKey(o2) && benchmarkRes.get(o2) == UNREACHABLE_VALUE) {
                return -1;
            }

            // sort accordingly to fixed order
            if (defOrder.contains(o1.getScheme()) && defOrder.contains(o2.getScheme())) {
                return defOrder.indexOf(o1.getScheme()) - defOrder.indexOf(o2.getScheme());
            }
            // the following code means that any protocol present in the default order
            // is preferred to any other protocol, currently this behavior is deactivated

            if (defOrder.contains(o1.getScheme())) {
                return -1;
            }
            if (defOrder.contains(o2.getScheme())) {
                return 1;
            }
            if (benchmarkRes.containsKey(o1) && benchmarkRes.containsKey(o2)) {
                // sort accordingly to benchmark results
                if (benchmarkRes.get(o1) > benchmarkRes.get(o2)) {
                    return -1;
                } else if (benchmarkRes.get(o2) > benchmarkRes.get(o1)) {
                    return 1;
                }
                return 0;
            }

            // undetermined, we have no info
            return 0;
        }
    });

    // finally remove unreachable protocols
    for (ListIterator<URI> it = output.listIterator(output.size()); it.hasPrevious();) {
        URI reachableOrNot = it.previous();
        if (benchmarkRes.containsKey(reachableOrNot) && benchmarkRes.get(reachableOrNot) == UNREACHABLE_VALUE) {
            if (!reachableOrNot.equals(defUri)) {
                it.remove();
            }
        } else {
            // we exit the loop at the first reachable protocol
            break;
        }
    }
    return output;
}

From source file:com.google.cloud.hadoop.util.HttpTransportFactory.java

/**
 * Parse an HTTP proxy from a String address.
 * @param proxyAddress The address of the proxy of the form (https?://)HOST:PORT.
 * @return The URI of the proxy.//from w w  w  . j a  va  2s  . c om
 * @throws IllegalArgumentException If the address is invalid.
 */
@VisibleForTesting
static URI parseProxyAddress(@Nullable String proxyAddress) {
    if (Strings.isNullOrEmpty(proxyAddress)) {
        return null;
    }
    String uriString = proxyAddress;
    if (!uriString.contains("//")) {
        uriString = "//" + uriString;
    }
    try {
        URI uri = new URI(uriString);
        String scheme = uri.getScheme();
        String host = uri.getHost();
        int port = uri.getPort();
        if (!Strings.isNullOrEmpty(scheme) && !scheme.matches("https?")) {
            throw new IllegalArgumentException(
                    String.format("HTTP proxy address '%s' has invalid scheme '%s'.", proxyAddress, scheme));
        } else if (Strings.isNullOrEmpty(host)) {
            throw new IllegalArgumentException(String.format("Proxy address '%s' has no host.", proxyAddress));
        } else if (port == -1) {
            throw new IllegalArgumentException(String.format("Proxy address '%s' has no port.", proxyAddress));
        } else if (!uri.equals(new URI(scheme, null, host, port, null, null, null))) {
            throw new IllegalArgumentException(String.format("Invalid proxy address '%s'.", proxyAddress));
        }
        return uri;
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(String.format("Invalid proxy address '%s'.", proxyAddress), e);
    }
}