List of usage examples for java.net URL toURI
public URI toURI() throws URISyntaxException
From source file:com.jaspersoft.studio.server.util.HttpUtils31.java
public static void setupProxy(HttpClient c, URL arg2, HostConfiguration config) { IProxyService proxyService = getProxyService(); if (proxyService == null) return;/*from w w w .jav a 2 s .c o m*/ IProxyData[] proxyDataForHost; try { proxyDataForHost = proxyService.select(arg2.toURI()); for (IProxyData data : proxyDataForHost) { if (data.isRequiresAuthentication()) { String userId = data.getUserId(); Credentials proxyCred = new UsernamePasswordCredentials(userId, data.getPassword()); // if the username is in the form "user\domain" // then use NTCredentials instead. int domainIndex = userId.indexOf("\\"); if (domainIndex > 0) { String domain = userId.substring(0, domainIndex); if (userId.length() > domainIndex + 1) { String user = userId.substring(domainIndex + 1); proxyCred = new NTCredentials(user, data.getPassword(), data.getHost(), domain); } } c.getState().setProxyCredentials(AuthScope.ANY, proxyCred); } config.setProxy(data.getHost(), data.getPort()); } // Close the service and close the service tracker proxyService = null; } catch (URISyntaxException e) { e.printStackTrace(); } }
From source file:org.apache.hadoop.gateway.GatewayAdminFuncTest.java
public static void setupLdap() throws Exception { URL usersUrl = getResourceUrl("users.ldif"); ldapTransport = new TcpTransport(0); ldap = new SimpleLdapDirectoryServer("dc=hadoop,dc=apache,dc=org", new File(usersUrl.toURI()), ldapTransport);/* w w w . ja v a 2s .com*/ ldap.start(); LOG.info("LDAP port = " + ldapTransport.getPort()); }
From source file:acromusashi.stream.resource.ResourceResolver.java
/** * Return target file path from resource's path. * * @param path resource's path/* w w w . jav a 2 s. c o m*/ * @return File object */ public static File resolve(String path) { Class<?> callerClass = resolveCaller(); URL url = callerClass.getResource(path); if (url == null) { return null; } File result; try { result = Paths.get(url.toURI()).toFile(); } catch (URISyntaxException ex) { return null; } return result; }
From source file:android.databinding.tool.util.GenerationalClassUtil.java
private static void buildCache() { L.d("building generational class cache"); ClassLoader classLoader = GenerationalClassUtil.class.getClassLoader(); Preconditions.check(classLoader instanceof URLClassLoader, "Class loader must be an" + "instance of URLClassLoader. %s", classLoader); //noinspection ConstantConditions final URLClassLoader urlClassLoader = (URLClassLoader) classLoader; sCache = new List[ExtensionFilter.values().length]; for (ExtensionFilter filter : ExtensionFilter.values()) { sCache[filter.ordinal()] = new ArrayList(); }/*from w ww .ja v a 2 s . com*/ for (URL url : urlClassLoader.getURLs()) { L.d("checking url %s for intermediate data", url); try { final File file = new File(url.toURI()); if (!file.exists()) { L.d("cannot load file for %s", url); continue; } if (file.isDirectory()) { // probably exported classes dir. loadFromDirectory(file); } else { // assume it is a zip file loadFomZipFile(file); } } catch (IOException | URISyntaxException e) { L.d("cannot open zip file from %s", url); } } }
From source file:org.mule.tools.rhinodo.impl.NodeModuleImplBuilder.java
private static URI getRoot(Class<?> klass, String rootDirectory) { ClassLoader classLoader = klass.getClassLoader(); URI root;/*from ww w .j ava 2s .c o m*/ try { URL resource = classLoader.getResource(rootDirectory); if (resource == null) { throw new IllegalArgumentException("Invalid resource at: " + rootDirectory); } root = resource.toURI(); } catch (URISyntaxException e) { throw new RuntimeException(e); } if (root == null) { throw new IllegalStateException("Error: path not found."); } try { root = new URI(root.toString() + "/"); } catch (URISyntaxException e) { throw new RuntimeException(e); } return root; }
From source file:ratpack.spring.config.RatpackProperties.java
static Path resourceToPath(URL resource) { Objects.requireNonNull(resource, "Resource URL cannot be null"); URI uri;/*from w w w . j a v a2 s. c om*/ try { uri = resource.toURI(); } catch (URISyntaxException e) { throw new IllegalArgumentException("Could not extract URI", e); } String scheme = uri.getScheme(); if (scheme.equals("file")) { String path = uri.toString().substring("file:".length()); if (path.contains("//")) { path = StringUtils.cleanPath(path.replace("//", "")); } return Paths.get(new FileSystemResource(path).getFile().toURI()); } if (!scheme.equals("jar")) { throw new IllegalArgumentException("Cannot convert to Path: " + uri); } String s = uri.toString(); int separator = s.indexOf("!/"); String entryName = s.substring(separator + 2); URI fileURI = URI.create(s.substring(0, separator)); FileSystem fs; try { fs = FileSystems.newFileSystem(fileURI, Collections.<String, Object>emptyMap()); return fs.getPath(entryName); } catch (IOException e) { throw new IllegalArgumentException("Could not create file system for resource: " + resource, e); } }
From source file:com.netflix.nicobar.core.testutil.CoreTestResourceUtil.java
/** * Locate the given script in the class path * @param script script identifier/*from w w w .ja v a2 s . co m*/ * @return absolute path to the test script */ public static Path getResourceAsPath(TestResource script) throws Exception { URL scriptUrl = Thread.currentThread().getContextClassLoader().getResource(script.getResourcePath()); if (scriptUrl == null) { fail("couldn't load resource " + script.getResourcePath()); } return Paths.get(scriptUrl.toURI()); }
From source file:jetbrains.exodus.util.ForkSupportIO.java
public static List<String> getClasspath(Class cls) { List<String> classpath = new ArrayList<>(); URL[] urls = ((URLClassLoader) cls.getClassLoader()).getURLs(); for (URL url : urls) { File f;/*from w ww . j a v a 2 s . co m*/ try { f = new File(url.toURI()); } catch (URISyntaxException e) { f = new File(url.getPath()); } classpath.add(f.getAbsolutePath()); } return classpath; }
From source file:net.sourceforge.ganttproject.gui.options.InterfaceOptionPageProvider.java
private static Pair<Boolean, File> checkLocale(Locale l) { if (Arrays.asList(DateFormat.getAvailableLocales()).contains(l)) { return Pair.create(Boolean.TRUE, null); }// www . java2s .co m File extDir = getExtDir(); if (!extDir.exists()) { return Pair.create(Boolean.FALSE, null); } if (!extDir.isDirectory()) { return Pair.create(Boolean.FALSE, null); } if (extDir.canWrite()) { GPLogger.logToLogger("Java extensions directory " + extDir + " is writable"); URL libUrl = InterfaceOptionPageProvider.class.getResource("lib"); if (libUrl != null) { try { File galicianLocaleJar = new File(new File(libUrl.toURI()), "javagalician.jar"); File targetJar = new File(extDir, galicianLocaleJar.getName()); GPLogger.logToLogger("Locale extension " + galicianLocaleJar); if (galicianLocaleJar.exists() && !targetJar.exists()) { GPLogger.logToLogger("Exists. Installing now"); FileUtils.copyFileToDirectory(galicianLocaleJar, extDir); return Pair.create(Boolean.TRUE, extDir); } } catch (IOException e) { GPLogger.log(e); } catch (URISyntaxException e) { GPLogger.log(e); } } return Pair.create(Boolean.FALSE, extDir); } else { GPLogger.logToLogger("Java extensions directory " + extDir + " is not writable"); } return Pair.create(Boolean.FALSE, extDir); }
From source file:com.katsu.dwm.reflection.JarUtils.java
/** * Retrieve all jar files in directoy// w w w . j a v a2s .c o m * @return array of jar {@link File Files} */ public static List<File> getJarFiles() { URLClassLoader sysloader = (URLClassLoader) JarUtils.class.getClassLoader(); URL[] urls = sysloader.getURLs(); List<File> result = new ArrayList<File>(); if (urls != null) { for (URL url : urls) { try { logger.trace("URL detected: " + url); if (url.getPath().toLowerCase().endsWith(".jar")) { result.add(new File(url.toURI())); } } catch (Exception e) { logger.error(e); } } } return result; }