java.net.URL#hashCode ( )源码实例Demo

下面列出了java.net.URL#hashCode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: uyuni   文件: TestUtils.java

/**
 * method to find a file relative to the calling class.  primarily
 * useful when writing tests that need access to external data.
 * this lets you put the data relative to the test class file.
 *
 * @param path the path, relative to caller's location
 * @return URL a URL referencing the file
 * @throws ClassNotFoundException if the calling class can not be found
 * (i.e., should not happen)
 * @throws IOException if the specified file in an archive (eg. jar) and
 * it cannot be copied to a temporary location
 */
public static URL findTestData(String path) throws ClassNotFoundException, IOException {
    Throwable t = new Throwable();
    StackTraceElement[] ste = t.getStackTrace();

    String className = ste[1].getClassName();
    Class clazz = Class.forName(className);

    URL ret = clazz.getResource(path);

    if (ret.toString().contains("!")) { // file is from an archive
        String tempPath = "/tmp/" + filePrefix + ret.hashCode();
        InputStream input = clazz.getResourceAsStream(path);

        OutputStream output = new FileOutputStream(tempPath);
        IOUtils.copy(input, output);

        return new File(tempPath).toURI().toURL();
    }

    return ret;
}
 
源代码2 项目: spacewalk   文件: TestUtils.java

/**
 * method to find a file relative to the calling class.  primarily
 * useful when writing tests that need access to external data.
 * this lets you put the data relative to the test class file.
 *
 * @param path the path, relative to caller's location
 * @return URL a URL referencing the file
 * @throws ClassNotFoundException if the calling class can not be found
 * (i.e., should not happen)
 * @throws IOException if the specified file in an archive (eg. jar) and
 * it cannot be copied to a temporary location
 */
public static URL findTestData(String path) throws ClassNotFoundException, IOException {
    Throwable t = new Throwable();
    StackTraceElement[] ste = t.getStackTrace();

    String className = ste[1].getClassName();
    Class clazz = Class.forName(className);

    URL ret = clazz.getResource(path);

    if (ret.toString().contains("!")) { // file is from an archive
        String tempPath = "/tmp/" + filePrefix + ret.hashCode();
        InputStream input = clazz.getResourceAsStream(path);

        OutputStream output = new FileOutputStream(tempPath);
        IOUtils.copy(input, output);

        return new File(tempPath).toURI().toURL();
    }

    return ret;
}
 

/**
 * Provides the hash calculation
 * @return an <tt>int</tt> suitable for hash table indexing
 */
@Override
protected int hashCode(URL u) {
  int h = 0;

  if (PROTOCOL.equals(u.getProtocol())) {
    final String host = u.getHost();
    if (host != null)
      h = host.hashCode();

    final String file = u.getFile();
    if (file != null)
      h += file.hashCode();

    h += u.getPort();
  } else {
    h = u.hashCode();
  }
  return h;
}
 
源代码4 项目: ghidra   文件: HelpLocation.java

@Override
public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + ((anchor == null) ? 0 : anchor.hashCode());
	result = prime * result + ((id == null) ? 0 : id.hashCode());
	result = prime * result + ((topic == null) ? 0 : topic.hashCode());

	URL helpURL = getURL();
	result = prime * result + ((helpURL == null) ? 0 : helpURL.hashCode());
	return result;
}
 
源代码5 项目: netbeans   文件: NbinstURLMapperTest.java

public void testURLNoInetAccess() throws MalformedURLException, IOException {
    URL url1 = new URL ("nbinst://test-module/modules/test.txt");   // NOI18N
    URL url2 = new URL ("nbinst://foo-module/modules/test.txt");    // NOI18N
    SecurityManager defaultManager = System.getSecurityManager();
    
    System.setSecurityManager(new InetSecurityManager());
    try {
        // make sure we do not try to resolve host name
        url1.hashCode();
        url1.equals(url2);
        testURLConnection();
    } finally {
        System.setSecurityManager(defaultManager);
    }
}
 
源代码6 项目: j2objc   文件: URLTest.java

public void testHashCodeAndEqualsDoesNotPerformNetworkIo() throws Exception {
    final BlockGuard.Policy oldPolicy = BlockGuard.getThreadPolicy();
    BlockGuard.setThreadPolicy(new BlockGuard.Policy() {
        @Override
        public void onWriteToDisk() {
            fail("Blockguard.Policy.onWriteToDisk");
        }

        @Override
        public void onReadFromDisk() {
            fail("Blockguard.Policy.onReadFromDisk");
        }

        @Override
        public void onNetwork() {
            fail("Blockguard.Policy.onNetwork");
        }

        @Override
        public int getPolicyMask() {
            return 0;
        }
    });

    try {
        URL url = new URL("http://www.google.com/");
        URL url2 = new URL("http://www.nest.com/");

        url.equals(url2);
        url2.hashCode();
    } finally {
        BlockGuard.setThreadPolicy(oldPolicy);
    }
}
 
源代码7 项目: dragonwell8_jdk   文件: MimeLauncher.java

protected String getTempFileName(URL url, String template) {
    String tempFilename = template;

    // Replace all but last occurrance of "%s" with timestamp to insure
    // uniqueness.  There's a subtle behavior here: if there is anything
    // _after_ the last "%s" we need to append it so that unusual launch
    // strings that have the datafile in the middle can still be used.
    int wildcard = tempFilename.lastIndexOf("%s");
    String prefix = tempFilename.substring(0, wildcard);

    String suffix = "";
    if (wildcard < tempFilename.length() - 2) {
        suffix = tempFilename.substring(wildcard + 2);
    }

    long timestamp = System.currentTimeMillis()/1000;
    int argIndex = 0;
    while ((argIndex = prefix.indexOf("%s")) >= 0) {
        prefix = prefix.substring(0, argIndex)
            + timestamp
            + prefix.substring(argIndex + 2);
    }

    // Add a file name and file-extension if known
    String filename = url.getFile();

    String extension = "";
    int dot = filename.lastIndexOf('.');

    // BugId 4084826:  Temp MIME file names not always valid.
    // Fix:  don't allow slashes in the file name or extension.
    if (dot >= 0 && dot > filename.lastIndexOf('/')) {
        extension = filename.substring(dot);
    }

    filename = "HJ" + url.hashCode();

    tempFilename = prefix + filename + timestamp + extension + suffix;

    return tempFilename;
}
 
源代码8 项目: TencentKona-8   文件: MimeLauncher.java

protected String getTempFileName(URL url, String template) {
    String tempFilename = template;

    // Replace all but last occurrance of "%s" with timestamp to insure
    // uniqueness.  There's a subtle behavior here: if there is anything
    // _after_ the last "%s" we need to append it so that unusual launch
    // strings that have the datafile in the middle can still be used.
    int wildcard = tempFilename.lastIndexOf("%s");
    String prefix = tempFilename.substring(0, wildcard);

    String suffix = "";
    if (wildcard < tempFilename.length() - 2) {
        suffix = tempFilename.substring(wildcard + 2);
    }

    long timestamp = System.currentTimeMillis()/1000;
    int argIndex = 0;
    while ((argIndex = prefix.indexOf("%s")) >= 0) {
        prefix = prefix.substring(0, argIndex)
            + timestamp
            + prefix.substring(argIndex + 2);
    }

    // Add a file name and file-extension if known
    String filename = url.getFile();

    String extension = "";
    int dot = filename.lastIndexOf('.');

    // BugId 4084826:  Temp MIME file names not always valid.
    // Fix:  don't allow slashes in the file name or extension.
    if (dot >= 0 && dot > filename.lastIndexOf('/')) {
        extension = filename.substring(dot);
    }

    filename = "HJ" + url.hashCode();

    tempFilename = prefix + filename + timestamp + extension + suffix;

    return tempFilename;
}
 
源代码9 项目: jdk8u60   文件: MimeLauncher.java

protected String getTempFileName(URL url, String template) {
    String tempFilename = template;

    // Replace all but last occurrance of "%s" with timestamp to insure
    // uniqueness.  There's a subtle behavior here: if there is anything
    // _after_ the last "%s" we need to append it so that unusual launch
    // strings that have the datafile in the middle can still be used.
    int wildcard = tempFilename.lastIndexOf("%s");
    String prefix = tempFilename.substring(0, wildcard);

    String suffix = "";
    if (wildcard < tempFilename.length() - 2) {
        suffix = tempFilename.substring(wildcard + 2);
    }

    long timestamp = System.currentTimeMillis()/1000;
    int argIndex = 0;
    while ((argIndex = prefix.indexOf("%s")) >= 0) {
        prefix = prefix.substring(0, argIndex)
            + timestamp
            + prefix.substring(argIndex + 2);
    }

    // Add a file name and file-extension if known
    String filename = url.getFile();

    String extension = "";
    int dot = filename.lastIndexOf('.');

    // BugId 4084826:  Temp MIME file names not always valid.
    // Fix:  don't allow slashes in the file name or extension.
    if (dot >= 0 && dot > filename.lastIndexOf('/')) {
        extension = filename.substring(dot);
    }

    filename = "HJ" + url.hashCode();

    tempFilename = prefix + filename + timestamp + extension + suffix;

    return tempFilename;
}
 
源代码10 项目: openjdk-jdk8u   文件: MimeLauncher.java

protected String getTempFileName(URL url, String template) {
    String tempFilename = template;

    // Replace all but last occurrance of "%s" with timestamp to insure
    // uniqueness.  There's a subtle behavior here: if there is anything
    // _after_ the last "%s" we need to append it so that unusual launch
    // strings that have the datafile in the middle can still be used.
    int wildcard = tempFilename.lastIndexOf("%s");
    String prefix = tempFilename.substring(0, wildcard);

    String suffix = "";
    if (wildcard < tempFilename.length() - 2) {
        suffix = tempFilename.substring(wildcard + 2);
    }

    long timestamp = System.currentTimeMillis()/1000;
    int argIndex = 0;
    while ((argIndex = prefix.indexOf("%s")) >= 0) {
        prefix = prefix.substring(0, argIndex)
            + timestamp
            + prefix.substring(argIndex + 2);
    }

    // Add a file name and file-extension if known
    String filename = url.getFile();

    String extension = "";
    int dot = filename.lastIndexOf('.');

    // BugId 4084826:  Temp MIME file names not always valid.
    // Fix:  don't allow slashes in the file name or extension.
    if (dot >= 0 && dot > filename.lastIndexOf('/')) {
        extension = filename.substring(dot);
    }

    filename = "HJ" + url.hashCode();

    tempFilename = prefix + filename + timestamp + extension + suffix;

    return tempFilename;
}
 
源代码11 项目: consulo   文件: WebImageUrlCache.java

public static int hashCode(URL url) {
  int i = url.hashCode();
  ourURLCache.putIfAbsent(i, url);
  return i;
}
 
源代码12 项目: Bytecoder   文件: MimeLauncher.java

protected String getTempFileName(URL url, String template) {
    String tempFilename = template;

    // Replace all but last occurrance of "%s" with timestamp to insure
    // uniqueness.  There's a subtle behavior here: if there is anything
    // _after_ the last "%s" we need to append it so that unusual launch
    // strings that have the datafile in the middle can still be used.
    int wildcard = tempFilename.lastIndexOf("%s");
    String prefix = tempFilename.substring(0, wildcard);

    String suffix = "";
    if (wildcard < tempFilename.length() - 2) {
        suffix = tempFilename.substring(wildcard + 2);
    }

    long timestamp = System.currentTimeMillis()/1000;
    int argIndex = 0;
    while ((argIndex = prefix.indexOf("%s")) >= 0) {
        prefix = prefix.substring(0, argIndex)
            + timestamp
            + prefix.substring(argIndex + 2);
    }

    // Add a file name and file-extension if known
    String filename = url.getFile();

    String extension = "";
    int dot = filename.lastIndexOf('.');

    // BugId 4084826:  Temp MIME file names not always valid.
    // Fix:  don't allow slashes in the file name or extension.
    if (dot >= 0 && dot > filename.lastIndexOf('/')) {
        extension = filename.substring(dot);
    }

    filename = "HJ" + url.hashCode();

    tempFilename = prefix + filename + timestamp + extension + suffix;

    return tempFilename;
}
 
源代码13 项目: openjdk-jdk9   文件: MimeLauncher.java

protected String getTempFileName(URL url, String template) {
    String tempFilename = template;

    // Replace all but last occurrance of "%s" with timestamp to insure
    // uniqueness.  There's a subtle behavior here: if there is anything
    // _after_ the last "%s" we need to append it so that unusual launch
    // strings that have the datafile in the middle can still be used.
    int wildcard = tempFilename.lastIndexOf("%s");
    String prefix = tempFilename.substring(0, wildcard);

    String suffix = "";
    if (wildcard < tempFilename.length() - 2) {
        suffix = tempFilename.substring(wildcard + 2);
    }

    long timestamp = System.currentTimeMillis()/1000;
    int argIndex = 0;
    while ((argIndex = prefix.indexOf("%s")) >= 0) {
        prefix = prefix.substring(0, argIndex)
            + timestamp
            + prefix.substring(argIndex + 2);
    }

    // Add a file name and file-extension if known
    String filename = url.getFile();

    String extension = "";
    int dot = filename.lastIndexOf('.');

    // BugId 4084826:  Temp MIME file names not always valid.
    // Fix:  don't allow slashes in the file name or extension.
    if (dot >= 0 && dot > filename.lastIndexOf('/')) {
        extension = filename.substring(dot);
    }

    filename = "HJ" + url.hashCode();

    tempFilename = prefix + filename + timestamp + extension + suffix;

    return tempFilename;
}
 
源代码14 项目: jdk8u-jdk   文件: MimeLauncher.java

protected String getTempFileName(URL url, String template) {
    String tempFilename = template;

    // Replace all but last occurrance of "%s" with timestamp to insure
    // uniqueness.  There's a subtle behavior here: if there is anything
    // _after_ the last "%s" we need to append it so that unusual launch
    // strings that have the datafile in the middle can still be used.
    int wildcard = tempFilename.lastIndexOf("%s");
    String prefix = tempFilename.substring(0, wildcard);

    String suffix = "";
    if (wildcard < tempFilename.length() - 2) {
        suffix = tempFilename.substring(wildcard + 2);
    }

    long timestamp = System.currentTimeMillis()/1000;
    int argIndex = 0;
    while ((argIndex = prefix.indexOf("%s")) >= 0) {
        prefix = prefix.substring(0, argIndex)
            + timestamp
            + prefix.substring(argIndex + 2);
    }

    // Add a file name and file-extension if known
    String filename = url.getFile();

    String extension = "";
    int dot = filename.lastIndexOf('.');

    // BugId 4084826:  Temp MIME file names not always valid.
    // Fix:  don't allow slashes in the file name or extension.
    if (dot >= 0 && dot > filename.lastIndexOf('/')) {
        extension = filename.substring(dot);
    }

    filename = "HJ" + url.hashCode();

    tempFilename = prefix + filename + timestamp + extension + suffix;

    return tempFilename;
}
 
源代码15 项目: hottub   文件: MimeLauncher.java

protected String getTempFileName(URL url, String template) {
    String tempFilename = template;

    // Replace all but last occurrance of "%s" with timestamp to insure
    // uniqueness.  There's a subtle behavior here: if there is anything
    // _after_ the last "%s" we need to append it so that unusual launch
    // strings that have the datafile in the middle can still be used.
    int wildcard = tempFilename.lastIndexOf("%s");
    String prefix = tempFilename.substring(0, wildcard);

    String suffix = "";
    if (wildcard < tempFilename.length() - 2) {
        suffix = tempFilename.substring(wildcard + 2);
    }

    long timestamp = System.currentTimeMillis()/1000;
    int argIndex = 0;
    while ((argIndex = prefix.indexOf("%s")) >= 0) {
        prefix = prefix.substring(0, argIndex)
            + timestamp
            + prefix.substring(argIndex + 2);
    }

    // Add a file name and file-extension if known
    String filename = url.getFile();

    String extension = "";
    int dot = filename.lastIndexOf('.');

    // BugId 4084826:  Temp MIME file names not always valid.
    // Fix:  don't allow slashes in the file name or extension.
    if (dot >= 0 && dot > filename.lastIndexOf('/')) {
        extension = filename.substring(dot);
    }

    filename = "HJ" + url.hashCode();

    tempFilename = prefix + filename + timestamp + extension + suffix;

    return tempFilename;
}
 
源代码16 项目: openjdk-8   文件: MimeLauncher.java

protected String getTempFileName(URL url, String template) {
    String tempFilename = template;

    // Replace all but last occurrance of "%s" with timestamp to insure
    // uniqueness.  There's a subtle behavior here: if there is anything
    // _after_ the last "%s" we need to append it so that unusual launch
    // strings that have the datafile in the middle can still be used.
    int wildcard = tempFilename.lastIndexOf("%s");
    String prefix = tempFilename.substring(0, wildcard);

    String suffix = "";
    if (wildcard < tempFilename.length() - 2) {
        suffix = tempFilename.substring(wildcard + 2);
    }

    long timestamp = System.currentTimeMillis()/1000;
    int argIndex = 0;
    while ((argIndex = prefix.indexOf("%s")) >= 0) {
        prefix = prefix.substring(0, argIndex)
            + timestamp
            + prefix.substring(argIndex + 2);
    }

    // Add a file name and file-extension if known
    String filename = url.getFile();

    String extension = "";
    int dot = filename.lastIndexOf('.');

    // BugId 4084826:  Temp MIME file names not always valid.
    // Fix:  don't allow slashes in the file name or extension.
    if (dot >= 0 && dot > filename.lastIndexOf('/')) {
        extension = filename.substring(dot);
    }

    filename = "HJ" + url.hashCode();

    tempFilename = prefix + filename + timestamp + extension + suffix;

    return tempFilename;
}
 
源代码17 项目: jdk8u_jdk   文件: MimeLauncher.java

protected String getTempFileName(URL url, String template) {
    String tempFilename = template;

    // Replace all but last occurrance of "%s" with timestamp to insure
    // uniqueness.  There's a subtle behavior here: if there is anything
    // _after_ the last "%s" we need to append it so that unusual launch
    // strings that have the datafile in the middle can still be used.
    int wildcard = tempFilename.lastIndexOf("%s");
    String prefix = tempFilename.substring(0, wildcard);

    String suffix = "";
    if (wildcard < tempFilename.length() - 2) {
        suffix = tempFilename.substring(wildcard + 2);
    }

    long timestamp = System.currentTimeMillis()/1000;
    int argIndex = 0;
    while ((argIndex = prefix.indexOf("%s")) >= 0) {
        prefix = prefix.substring(0, argIndex)
            + timestamp
            + prefix.substring(argIndex + 2);
    }

    // Add a file name and file-extension if known
    String filename = url.getFile();

    String extension = "";
    int dot = filename.lastIndexOf('.');

    // BugId 4084826:  Temp MIME file names not always valid.
    // Fix:  don't allow slashes in the file name or extension.
    if (dot >= 0 && dot > filename.lastIndexOf('/')) {
        extension = filename.substring(dot);
    }

    filename = "HJ" + url.hashCode();

    tempFilename = prefix + filename + timestamp + extension + suffix;

    return tempFilename;
}
 
源代码18 项目: spotbugs   文件: BlockingMethodsOnURLs.java

static int f(URL u) {
    return u.hashCode();
}
 
源代码19 项目: jdk8u-jdk   文件: MimeLauncher.java

protected String getTempFileName(URL url, String template) {
    String tempFilename = template;

    // Replace all but last occurrance of "%s" with timestamp to insure
    // uniqueness.  There's a subtle behavior here: if there is anything
    // _after_ the last "%s" we need to append it so that unusual launch
    // strings that have the datafile in the middle can still be used.
    int wildcard = tempFilename.lastIndexOf("%s");
    String prefix = tempFilename.substring(0, wildcard);

    String suffix = "";
    if (wildcard < tempFilename.length() - 2) {
        suffix = tempFilename.substring(wildcard + 2);
    }

    long timestamp = System.currentTimeMillis()/1000;
    int argIndex = 0;
    while ((argIndex = prefix.indexOf("%s")) >= 0) {
        prefix = prefix.substring(0, argIndex)
            + timestamp
            + prefix.substring(argIndex + 2);
    }

    // Add a file name and file-extension if known
    String filename = url.getFile();

    String extension = "";
    int dot = filename.lastIndexOf('.');

    // BugId 4084826:  Temp MIME file names not always valid.
    // Fix:  don't allow slashes in the file name or extension.
    if (dot >= 0 && dot > filename.lastIndexOf('/')) {
        extension = filename.substring(dot);
    }

    filename = "HJ" + url.hashCode();

    tempFilename = prefix + filename + timestamp + extension + suffix;

    return tempFilename;
}
 
源代码20 项目: jdk8u-dev-jdk   文件: MimeLauncher.java

protected String getTempFileName(URL url, String template) {
    String tempFilename = template;

    // Replace all but last occurrance of "%s" with timestamp to insure
    // uniqueness.  There's a subtle behavior here: if there is anything
    // _after_ the last "%s" we need to append it so that unusual launch
    // strings that have the datafile in the middle can still be used.
    int wildcard = tempFilename.lastIndexOf("%s");
    String prefix = tempFilename.substring(0, wildcard);

    String suffix = "";
    if (wildcard < tempFilename.length() - 2) {
        suffix = tempFilename.substring(wildcard + 2);
    }

    long timestamp = System.currentTimeMillis()/1000;
    int argIndex = 0;
    while ((argIndex = prefix.indexOf("%s")) >= 0) {
        prefix = prefix.substring(0, argIndex)
            + timestamp
            + prefix.substring(argIndex + 2);
    }

    // Add a file name and file-extension if known
    String filename = url.getFile();

    String extension = "";
    int dot = filename.lastIndexOf('.');

    // BugId 4084826:  Temp MIME file names not always valid.
    // Fix:  don't allow slashes in the file name or extension.
    if (dot >= 0 && dot > filename.lastIndexOf('/')) {
        extension = filename.substring(dot);
    }

    filename = "HJ" + url.hashCode();

    tempFilename = prefix + filename + timestamp + extension + suffix;

    return tempFilename;
}