List of usage examples for java.net URL getFile
public String getFile()
From source file:CookieUtils.java
/** * Does the cookie path match the URL "file"? * /* ww w.ja v a 2 s . co m*/ * @param url * URL to match * @param cookie * CookieData object (the cookie) * @return true if the cookie domain matches the URL */ public static boolean inPath(URL url, CookieData cookie) { return url.getFile().startsWith(cookie.getPath()); }
From source file:com.galenframework.utils.GalenUtils.java
public static File findFile(String specFile) { URL resource = GalenUtils.class.getResource(specFile); if (resource != null) { return new File(resource.getFile()); } else//from ww w . j a va 2s . c o m return new File(specFile); }
From source file:org.jamwiki.utils.WikiLogger.java
/** * *///from w ww. ja v a 2s . c o m private static File loadProperties() throws Exception { ClassLoader loader = ClassUtils.getDefaultClassLoader(); URL url = loader.getResource(LOG_PROPERTIES_FILENAME); if (url == null) { throw new Exception("Log initialization file " + LOG_PROPERTIES_FILENAME + " could not be found"); } File propertyFile = new File(URLDecoder.decode(url.getFile(), "UTF-8")); if (!propertyFile.exists()) { throw new Exception("Log initialization file " + LOG_PROPERTIES_FILENAME + " could not be found"); } return propertyFile; }
From source file:net.rptools.lib.FileUtil.java
public static String getNameWithoutExtension(URL url) { String file = url.getFile(); try {/* www. j a va 2s .c om*/ file = url.toURI().getPath(); // int beginning = file.lastIndexOf(File.separatorChar); // Don't need to strip the path since the File() constructor will take care of that // file = file.substring(beginning < 0 ? 0 : beginning + 1); } catch (URISyntaxException e) { // If the conversion doesn't work, ignore it and use the original file name. } return getNameWithoutExtension(new File(file)); }
From source file:org.jodconverter.office.OnlineOfficeManagerPoolEntry.java
private static File getFile(final URL url) { try {// w w w . j a va 2s.c om return new File(new URI(StringUtils.replace(url.toString(), " ", "%20")).getSchemeSpecificPart()); } catch (URISyntaxException ex) { // Fallback for URLs that are not valid URIs (should hardly ever happen). return new File(url.getFile()); } }
From source file:Urls.java
public static String getNoRefForm(URL url) { String host = url.getHost();/*from w w w.j av a2 s.com*/ int port = url.getPort(); String portText = port == -1 ? "" : ":" + port; String userInfo = url.getUserInfo(); String userInfoText = userInfo == null || userInfo.length() == 0 ? "" : userInfo + "@"; String hostPort = host == null || host.length() == 0 ? "" : "//" + userInfoText + host + portText; return url.getProtocol() + ":" + hostPort + url.getFile(); }
From source file:com.joyent.manta.config.TestConfigContext.java
static ConfigContext buildTestContext(String mantaUrl, String mantaUser, String mantaKeyPath, String mantaKeyId, Integer mantaTimeout, Integer retries) { URL privateKeyUrl = mantaKeyPath == null ? null : Thread.currentThread().getContextClassLoader().getResource(mantaKeyPath); BaseChainedConfigContext testConfig = new StandardConfigContext().setMantaURL(mantaUrl) .setMantaUser(mantaUser).setMantaKeyId(mantaKeyId).setTimeout(mantaTimeout).setRetries(retries); if (privateKeyUrl != null) { testConfig.setMantaKeyPath(privateKeyUrl.getFile()); } else {/*from w w w . j ava 2 s. com*/ testConfig.setMantaKeyPath(mantaKeyPath); } return testConfig; }
From source file:io.lightlink.utils.ClasspathScanUtils.java
public static List<String> getResourcesFromPackage(String packageName) throws IOException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Enumeration<URL> packageURLs; ArrayList<String> names = new ArrayList<String>(); packageName = packageName.replace(".", "/"); packageURLs = classLoader.getResources(packageName); while (packageURLs.hasMoreElements()) { URL packageURL = packageURLs.nextElement(); // loop through files in classpath if (packageURL.getProtocol().equals("jar")) { String jarFileName;// w w w . j ava 2 s. c o m JarFile jf; Enumeration<JarEntry> jarEntries; String entryName; // build jar file name, then loop through zipped entries jarFileName = URLDecoder.decode(packageURL.getFile(), "UTF-8"); jarFileName = jarFileName.substring(5, jarFileName.indexOf("!")); jf = new JarFile(jarFileName); jarEntries = jf.entries(); while (jarEntries.hasMoreElements()) { entryName = jarEntries.nextElement().getName(); if (entryName.startsWith(packageName) && entryName.length() > packageName.length() + 5) { entryName = entryName.substring(packageName.length()); names.add(entryName); } } } else { findFromDirectory(packageURL, names); } } return names; }
From source file:com.swordlord.gozer.builder.Parser.java
/** * Helper class for getClasses and getPackageNames (using Delegation) * //from w w w . jav a2s .c om * @param pckgname * @return * @throws ClassNotFoundException */ private static File getClassesHelper(String pckgname) throws ClassNotFoundException { // Get a File object for the package File directory = null; try { ClassLoader cld = Thread.currentThread().getContextClassLoader(); if (cld == null) { throw new ClassNotFoundException("Can't get class loader."); } String path = pckgname.replace('.', '/'); URL resource = cld.getResource(path); if (resource == null) { throw new ClassNotFoundException("No resource for " + path); } directory = new File(resource.getFile()); return directory; } catch (NullPointerException x) { throw new ClassNotFoundException( pckgname + " (" + directory + ") does not appear to be a valid package"); } }
From source file:com.impetus.kundera.loader.PersistenceXMLLoader.java
/** * Returns persistence unit root url/*from w ww .ja v a 2 s .co m*/ * * @param url * raw url * @return rootUrl rootUrl */ private static URL getPersistenceRootUrl(URL url) { String f = url.getFile(); f = parseFilePath(f); URL jarUrl = url; try { if (AllowedProtocol.isJarProtocol(url.getProtocol())) { jarUrl = new URL(f); if (jarUrl.getProtocol() != null && AllowedProtocol.FILE.name().equals(jarUrl.getProtocol().toUpperCase()) && StringUtils.contains(f, " ")) { jarUrl = new File(f).toURI().toURL(); } } else if (AllowedProtocol.isValidProtocol(url.getProtocol())) { if (StringUtils.contains(f, " ")) { jarUrl = new File(f).toURI().toURL(); } else { jarUrl = new File(f).toURL(); } } } catch (MalformedURLException mex) { log.error("Error during getPersistenceRootUrl(), Caused by: {}.", mex); throw new IllegalArgumentException("Invalid jar URL[] provided!" + url); } return jarUrl; }