本文整理汇总了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);
}
}
示例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;
}