Java Code Examples for java.net.URL#hashCode()
The following examples show how to use
java.net.URL#hashCode() .
These examples are extracted from open source projects.
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 Project: uyuni File: TestUtils.java License: 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 Project: spacewalk File: TestUtils.java License: 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 3
Source Project: knopflerfish.org File: BundleURLStreamHandler.java License: 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 4
Source Project: ghidra File: HelpLocation.java License: 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 Project: netbeans File: NbinstURLMapperTest.java License: 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 Project: j2objc File: URLTest.java License: 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 Project: dragonwell8_jdk File: MimeLauncher.java License: 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 Project: TencentKona-8 File: MimeLauncher.java License: 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 Project: jdk8u60 File: MimeLauncher.java License: 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 Project: openjdk-jdk8u File: MimeLauncher.java License: 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 11
Source Project: consulo File: WebImageUrlCache.java License: Apache License 2.0 | 4 votes |
public static int hashCode(URL url) { int i = url.hashCode(); ourURLCache.putIfAbsent(i, url); return i; }
Example 12
Source Project: Bytecoder File: MimeLauncher.java License: 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 13
Source Project: openjdk-jdk9 File: MimeLauncher.java License: 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 Project: jdk8u-jdk File: MimeLauncher.java License: 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 Project: hottub File: MimeLauncher.java License: 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 Project: openjdk-8 File: MimeLauncher.java License: 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 17
Source Project: jdk8u_jdk File: MimeLauncher.java License: 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 18
Source Project: spotbugs File: BlockingMethodsOnURLs.java License: GNU Lesser General Public License v2.1 | 4 votes |
static int f(URL u) { return u.hashCode(); }
Example 19
Source Project: jdk8u-jdk File: MimeLauncher.java License: 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 Project: jdk8u-dev-jdk File: MimeLauncher.java License: 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; }