當前位置: 首頁>>代碼示例>>Java>>正文


Java URL.hashCode方法代碼示例

本文整理匯總了Java中java.net.URL.hashCode方法的典型用法代碼示例。如果您正苦於以下問題:Java URL.hashCode方法的具體用法?Java URL.hashCode怎麽用?Java URL.hashCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.URL的用法示例。


在下文中一共展示了URL.hashCode方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testURLNoInetAccess

import java.net.URL; //導入方法依賴的package包/類
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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:NbinstURLMapperTest.java

示例2: getTempFileName

import java.net.URL; //導入方法依賴的package包/類
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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:42,代碼來源:MimeLauncher.java


注:本文中的java.net.URL.hashCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。