Example usage for java.net URL sameFile

List of usage examples for java.net URL sameFile

Introduction

In this page you can find the example usage for java.net URL sameFile.

Prototype

public boolean sameFile(URL other) 

Source Link

Document

Compares two URLs, excluding the fragment component.

Returns true if this URL and the other argument are equal without taking the fragment component into consideration.

Usage

From source file:org.n52.youngs.test.DirectorySourceTestDisabled.java

@Test
public void fileUrl() throws MalformedURLException {
    DirectorySource source = new DirectorySource(baseDirectory.resolve("csw"));
    URL endpoint = source.getEndpoint();
    // probably everything is already good at this point
    assertThat("beginning of url is file:/", endpoint.toExternalForm(), startsWith("file:/"));
    assertThat("end of url is directories", endpoint.getPath(), endsWith("records/csw/"));
    assertThat("file is correct", endpoint.sameFile(baseDirectory.resolve("csw").toFile().toURI().toURL()),
            is(true));//from   ww  w  .j a  v a2 s. c  om
}

From source file:org.webical.test.plugin.classloading.PluginClassLoaderTest.java

/**
 * Tests resource loading from the classpath
 *///  w  w w .  java2s. co m
public void testResourceLoading() {
    File resourceFile = new File(getClass().getResource("test-resource.txt").getFile());
    log.info("testResourceLoading:File " + resourceFile.toString());
    try {
        classLoader.addClassPathResourceRegistration(
                ClassUtils.fileToClassPathResourceIdentifier(resourceFile.getParentFile(), resourceFile),
                resourceFile);
    } catch (DuplicateClassPathEntryException e) {
        fail("What is it with those duplicates...");
    }

    URL resourceUrl = classLoader.findResource("test-resource.txt");
    log.info("testResourceLoading:URL " + resourceUrl.toString());
    try {
        if (resourceUrl == null || !resourceUrl.sameFile(resourceFile.toURI().toURL())) {
            fail("Could not successfully load the resource");
        }
    } catch (MalformedURLException e) {
        fail("Malformed url registered used");
    }
}