Java Code Examples for java.net.URL#hashCode()
The following examples show how to use
java.net.URL#hashCode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestUtils.java From uyuni with GNU General Public License v2.0 | 6 votes |
/**
* 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;
}
Example 2
Source File: BundleURLStreamHandler.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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; }
Example 3
Source File: TestUtils.java From spacewalk with GNU General Public License v2.0 | 6 votes |
/**
* 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;
}
Example 4
Source File: HelpLocation.java From ghidra with Apache License 2.0 | 5 votes |
@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; }
Example 5
Source File: NbinstURLMapperTest.java From netbeans with Apache License 2.0 | 5 votes |
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);
}
}
Example 6
Source File: URLTest.java From j2objc with Apache License 2.0 | 5 votes |
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);
}
}
Example 7
Source File: MimeLauncher.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
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;
}
Example 8
Source File: MimeLauncher.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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;
}
Example 9
Source File: MimeLauncher.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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;
}
Example 10
Source File: BlockingMethodsOnURLs.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
static int f(URL u) {
return u.hashCode();
}
Example 11
Source File: MimeLauncher.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
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;
}
Example 12
Source File: MimeLauncher.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
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;
}
Example 13
Source File: MimeLauncher.java From hottub with GNU General Public License v2.0 | 4 votes |
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;
}
Example 14
Source File: MimeLauncher.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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;
}
Example 15
Source File: MimeLauncher.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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;
}
Example 16
Source File: MimeLauncher.java From Bytecoder with Apache License 2.0 | 4 votes |
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;
}
Example 17
Source File: WebImageUrlCache.java From consulo with Apache License 2.0 | 4 votes |
public static int hashCode(URL url) { int i = url.hashCode(); ourURLCache.putIfAbsent(i, url); return i; }
Example 18
Source File: MimeLauncher.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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;
}
Example 19
Source File: MimeLauncher.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
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;
}
Example 20
Source File: MimeLauncher.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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;
}