java.net.URL.sameFile()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中java.net.URL.sameFile()方法的一些代码示例,展示了URL.sameFile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URL.sameFile()方法的具体详情如下:
包路径:java.net.URL
类名称:URL
方法名:sameFile

URL.sameFile介绍

[英]Returns true if this URL refers to the same resource as otherURL. All URL components except the reference field are compared.
[中]如果此URL引用与其他URL相同的资源,则返回true。将比较除引用字段之外的所有URL组件。

代码示例

代码示例来源:origin: robovm/robovm

/**
 * Indicates whether this package is sealed with respect to the specified
 * URL.
 *
 * @param url
 *            the URL to check.
 * @return {@code true} if this package is sealed with {@code url}; {@code
 *         false} otherwise
 */
public boolean isSealed(URL url) {
  return sealBase != null && sealBase.sameFile(url);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testPersistenceUnitRootUrlWithJar() throws Exception {
  ClassPathResource archive = new ClassPathResource("/org/springframework/orm/jpa/jpa-archive.jar");
  String newRoot = "jar:" + archive.getURL().toExternalForm() + "!/META-INF/persist.xml";
  Resource insideArchive = new UrlResource(newRoot);
  // make sure the location actually exists
  assertTrue(insideArchive.exists());
  URL url = PersistenceUnitReader.determinePersistenceUnitRootUrl(insideArchive);
  assertTrue("the archive location should have been returned", archive.getURL().sameFile(url));
}

代码示例来源:origin: org.eclipse.jetty/jetty-util

/**
   * Check if this jar:file: resource is contained in the
   * named resource. Eg <code>jar:file:///a/b/c/foo.jar!/x.html</code> isContainedIn <code>file:///a/b/c/foo.jar</code>
   * @param resource the resource to test for
   * @return true if resource is contained in the named resource
   * @throws MalformedURLException if unable to process is contained due to invalid URL format
   */
  @Override
  public boolean isContainedIn (Resource resource) 
  throws MalformedURLException
  {
    String string = _urlString;
    int index = string.lastIndexOf("!/");
    if (index > 0)
      string = string.substring(0,index);
    if (string.startsWith("jar:"))
      string = string.substring(4);
    URL url = new URL(string);
    return url.sameFile(resource.getURI().toURL());     
  }
}

代码示例来源:origin: RaiMan/SikuliX2

public int get(Object args) {
 URL given = asURL(args);
 if (SX.isNotSet(given)) {
  return -1;
 }
 int n = 0;
 for (URL path : pathList) {
  if (given.sameFile(path)) {
   return n;
  }
  n++;
 }
 return -1;
}

代码示例来源:origin: org.netbeans.api/org-openide-awt

URL requestedURL;
synchronized (rp) {
  if ((this.url != null) && this.url.sameFile(url)) {
    Document doc = swingBrowser.getDocument();

代码示例来源:origin: MobiVM/robovm

/**
 * Indicates whether this package is sealed with respect to the specified
 * URL.
 *
 * @param url
 *            the URL to check.
 * @return {@code true} if this package is sealed with {@code url}; {@code
 *         false} otherwise
 */
public boolean isSealed(URL url) {
  return sealBase != null && sealBase.sameFile(url);
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * Indicates whether this package is sealed with respect to the specified
 * URL.
 *
 * @param url
 *            the URL to check.
 * @return {@code true} if this package is sealed with {@code url}; {@code
 *         false} otherwise
 */
public boolean isSealed(URL url) {
  return sealBase != null && sealBase.sameFile(url);
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * Indicates whether this package is sealed with respect to the specified
 * URL.
 *
 * @param url
 *            the URL to check.
 * @return {@code true} if this package is sealed with {@code url}; {@code
 *         false} otherwise
 */
public boolean isSealed(URL url) {
  return sealBase != null && sealBase.sameFile(url);
}

代码示例来源:origin: ibinti/bugvm

/**
 * Indicates whether this package is sealed with respect to the specified
 * URL.
 *
 * @param url
 *            the URL to check.
 * @return {@code true} if this package is sealed with {@code url}; {@code
 *         false} otherwise
 */
public boolean isSealed(URL url) {
  return sealBase != null && sealBase.sameFile(url);
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Indicates whether this package is sealed with respect to the specified
 * URL.
 *
 * @param url
 *            the URL to check.
 * @return {@code true} if this package is sealed with {@code url}; {@code
 *         false} otherwise
 */
public boolean isSealed(URL url) {
  return sealBase != null && sealBase.sameFile(url);
}

代码示例来源:origin: FlexoVM/flexovm

/**
 * Indicates whether this package is sealed with respect to the specified
 * URL.
 *
 * @param url
 *            the URL to check.
 * @return {@code true} if this package is sealed with {@code url}; {@code
 *         false} otherwise
 */
public boolean isSealed(URL url) {
  return sealBase != null && sealBase.sameFile(url);
}

代码示例来源:origin: EvoSuite/evosuite

public static boolean sameFile(URL url, URL other) {
  return url.sameFile(other);
}

代码示例来源:origin: girtel/Net2Plan

@Override
  public int compare(URL o1, URL o2)
  {
    if (o1.sameFile(o2)) return 0;
    else return o1.toString().compareTo(o2.toString());
  }
}

代码示例来源:origin: freeplane/freeplane

private boolean sameFile(final URL urlToCheck, final URL mapViewUrl) {
  if (mapViewUrl == null) {
    return false;
  }
  if (urlToCheck.getProtocol().equals("file") && mapViewUrl.getProtocol().equals("file")) {
    return (new File(urlToCheck.getFile())).equals(new File(mapViewUrl.getFile()));
  }
  return urlToCheck.sameFile(mapViewUrl);
}

代码示例来源:origin: stackoverflow.com

>URL url1 = new URL("http://stackoverflow.com/foo");

>URL url2 = new URL("http://stackoverflow.com/foo/");

>System.out.println(url1.sameFile(url2));

// this is suggested by Joachim Sauer 
>URI uri = new URI("http://stackoverflow.com/foo/");
>System.out.println(uri.equals("http://stackoverflow.com/foo"));

// Both are giving same result

代码示例来源:origin: com.mycila.maven-license-plugin/maven-license-plugin

public boolean is(Header header) {
  try {
    return header.getLocation().sameFile(this.file.toURI().toURL());
  }
  catch (Exception e) {
    throw new IllegalStateException("Error comparing document " + this.file + " with file " + file + ". Cause: " + e.getMessage(), e);
  }
}

代码示例来源:origin: org.wisdom-framework/thymeleaf-template-engine

/**
 * Gets the template object using the given url as backend.
 *
 * @param url the url
 * @return the template object, {@literal null} if not found
 */
private ThymeLeafTemplateImplementation getTemplateByURL(URL url) {
  Collection<ThymeLeafTemplateImplementation> list = registrations.keySet();
  for (ThymeLeafTemplateImplementation template : list) {
    if (template.getURL().sameFile(url)) {
      return template;
    }
  }
  return null;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-spring-beans

private static boolean hasClassPathesIdenticEntries(ClassPath cp1, ClassPath cp2) {
  if (cp1.entries().size() != cp2.entries().size()) {
    return false;
  }
  for (int i = 0; i < cp1.entries().size(); i++) {
    if (!cp1.entries().get(i).getURL().sameFile(cp2.entries().get(i).getURL())) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: shrinkwrap/shrinkwrap

@Test
public void shouldBeAbleToReturnURL() throws Exception {
  final URL url = getThreadContextClassLoader().getResource(EXISTING_RESOURCE);
  final Asset asset = new UrlAsset(url);
  
  Assert.assertTrue(url.sameFile(((UrlAsset)asset).getSource()));
}

代码示例来源:origin: com.axway.ats.framework/ats-uiengine

private boolean isAlreadyLoadedByAncestor(
                      final URL url,
                      HtmlPage page ) {
  WebWindow window = page.getEnclosingWindow();
  while (window != null) {
    if (url.sameFile(window.getEnclosedPage().getWebResponse().getWebRequest().getUrl())) {
      return true;
    }
    if (window == window.getParentWindow()) {
      window = null;
    } else {
      window = window.getParentWindow();
    }
  }
  return false;
}

相关文章