List of usage examples for java.net URL getPath
public String getPath()
From source file:com.hp.mercury.ci.jenkins.plugins.OOBuildStep.java
public static URI URI(String urlString) { try {//from w w w .j av a 2s . c o m final URL url = new URL(urlString); return new URI(url.getProtocol(), null, url.getHost(), url.getPort(), url.getPath(), url.getQuery(), null); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:fr.cls.atoll.motu.processor.wps.TestServiceMetadata.java
public static void testServiceMetadataBuilder() { ServiceMetadataBuilder serviceMetadataBuilder = new ServiceMetadataBuilder(); URL url = null; try {//from w w w.jav a 2 s . c o m url = Organizer.findResource("fmpp/src/base/serviceMetadataTemplateOpendapBase.xml"); } catch (MotuException e) { // TODO Auto-generated catch block e.printStackTrace(); } serviceMetadataBuilder.setXmlTemplate(url.getPath()); serviceMetadataBuilder.setTempPath("file:///c:/tempVFS"); serviceMetadataBuilder.setOutputXml( "file:///J:/dev/atoll-v2/atoll-motu/atoll-motu-processor/src/main/resources/fmpp/src/ServiceMetadataOpendap.xml"); serviceMetadataBuilder.setValidate(false); serviceMetadataBuilder.setExpand(false); serviceMetadataBuilder.setFmpp(false); serviceMetadataBuilder.setValidateOutput("src/main/resources/fmpp/out"); serviceMetadataBuilder.execute(); }
From source file:io.sloeber.core.managers.Manager.java
private static void loadLibraryIndex(boolean download) { try {//from w ww. j a v a 2s . c o m URL librariesUrl = new URL(Defaults.LIBRARIES_URL); String localFileName = Paths.get(librariesUrl.getPath()).getFileName().toString(); File librariesFile = ConfigurationPreferences.getInstallationPath().append(localFileName).toFile(); if (!librariesFile.exists() || download) { librariesFile.getParentFile().mkdirs(); myCopy(librariesUrl, librariesFile); } if (librariesFile.exists()) { try (InputStreamReader reader = new InputStreamReader(new FileInputStream(librariesFile), Charset.forName("UTF8"))) { //$NON-NLS-1$ libraryIndex = new Gson().fromJson(reader, LibraryIndex.class); libraryIndex.resolve(); } } } catch (IOException e) { Common.log(new Status(IStatus.WARNING, Activator.getId(), "Failed to load library index", e)); //$NON-NLS-1$ } }
From source file:com.depas.utils.FileUtils.java
private static String getConfigDirectoryPath(Class<?> c, String rootDirectory) { // get url to iwc/idc directory on classpath try {// w w w . j a v a 2 s.c om URL url = ClassLoader.getSystemResource(rootDirectory); if (url == null) { // try this classpath, for running in eclipse url = c.getClassLoader().getResource(rootDirectory); } if (url != null) { String path = url.getPath(); if (!path.endsWith("\\") && !path.endsWith("/")) { path += "/"; } return URLDecoder.decode(path, "UTF-8"); } else { return null; } } catch (Exception ex) { logger.warn("Error obtaining file path to '" + rootDirectory + "' config directory: " + ex); return null; } }
From source file:ml.shifu.dtrain.DTrainRequestProcessor.java
/** * Find a jar that contains a class of the same name, if any. It will return a jar file, even if that is not the * first thing on the class path that has a class with the same name. * //from www.j ava 2 s .c o m * @param myClass * the class to find * @return a jar file that contains the class, or null */ @SuppressWarnings("rawtypes") private static String findContainingJar(Class myClass) { ClassLoader loader = myClass.getClassLoader(); String classFile = myClass.getName().replaceAll("\\.", "/") + ".class"; try { for (Enumeration itr = loader.getResources(classFile); itr.hasMoreElements();) { URL url = (URL) itr.nextElement(); if ("jar".equals(url.getProtocol())) { String toReturn = url.getPath(); if (toReturn.startsWith("file:")) { toReturn = toReturn.substring("file:".length()); } // URLDecoder is a misnamed class, since it actually decodes // x-www-form-urlencoded MIME type rather than actual // URL encoding (which the file path has). Therefore it // would // decode +s to ' 's which is incorrect (spaces are actually // either unencoded or encoded as "%20"). Replace +s first, // so // that they are kept sacred during the decoding process. toReturn = toReturn.replaceAll("\\+", "%2B"); toReturn = URLDecoder.decode(toReturn, "UTF-8"); return toReturn.replaceAll("!.*$", ""); } else if ("file".equals(url.getProtocol())) { String toReturn = url.getPath(); toReturn = toReturn.replaceAll("\\+", "%2B"); toReturn = URLDecoder.decode(toReturn, "UTF-8"); return toReturn.replaceAll("!.*$", ""); } } } catch (IOException e) { throw new RuntimeException(e); } return null; }
From source file:ml.shifu.guagua.yarn.GuaguaYarnClient.java
/** * Find a jar that contains a class of the same name, if any. It will return a jar file, even if that is not the * first thing on the class path that has a class with the same name. * //from w w w .ja v a 2s . com * @param my_class * the class to find. * @return a jar file that contains the class, or null. * @throws IOException * in case when read class file. */ private static String findContainingJar(Class<?> my_class) { ClassLoader loader = my_class.getClassLoader(); String class_file = my_class.getName().replaceAll("\\.", "/") + ".class"; try { for (Enumeration<?> itr = loader.getResources(class_file); itr.hasMoreElements();) { URL url = (URL) itr.nextElement(); if ("jar".equals(url.getProtocol())) { String toReturn = url.getPath(); if (toReturn.startsWith("file:")) { toReturn = toReturn.substring("file:".length()); } // URLDecoder is a misnamed class, since it actually decodes // x-www-form-urlencoded MIME type rather than actual // URL encoding (which the file path has). Therefore it would // decode +s to ' 's which is incorrect (spaces are actually // either unencoded or encoded as "%20"). Replace +s first, so // that they are kept sacred during the decoding process. toReturn = toReturn.replaceAll("\\+", "%2B"); toReturn = URLDecoder.decode(toReturn, "UTF-8"); return toReturn.replaceAll("!.*$", ""); } } } catch (IOException e) { throw new RuntimeException(e); } return null; }
From source file:com.odoko.solrcli.actions.CrawlPostAction.java
/** * Appends to the path of the URL/* w ww.j a v a2 s. co m*/ * @param url the URL * @param append the path to append * @return the final URL version */ protected static URL appendUrlPath(URL url, String append) throws MalformedURLException { return new URL(url.getProtocol() + "://" + url.getAuthority() + url.getPath() + append + (url.getQuery() != null ? "?"+url.getQuery() : "")); }
From source file:fr.eolya.utils.http.HttpUtils.java
public static String urlGetFileName(String url) { try {//from ww w .ja va 2s . co m URL u = new URL(url); String name = u.getPath(); if (name.lastIndexOf("/") != -1 && name.lastIndexOf("/") < name.length()) name = name.substring(name.lastIndexOf("/") + 1); return name; } catch (Exception e) { } return ""; }
From source file:org.hawkular.wildfly.agent.itest.util.AbstractITest.java
public static void writeNode(Class<?> caller, ModelNode node, String nodeFileName) throws UnsupportedEncodingException, FileNotFoundException { URL callerUrl = caller.getResource(caller.getSimpleName() + ".class"); if (!callerUrl.getProtocol().equals("file")) { throw new IllegalStateException(AbstractITest.class.getName() + ".store() works only if the caller's class file is loaded using a file:// URL."); }/*from w ww. java 2 s .c om*/ String callerUrlPath = callerUrl.getPath(); String nodePath = callerUrlPath.replaceAll("\\.class$", "." + nodeFileName); nodePath = nodePath.replace("/target/test-classes/", "/src/test/resources/"); System.out.println("Storing a node to [" + nodePath + "]"); File outputFile = new File(nodePath); if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } try (PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "utf-8"))) { node.writeString(out, false); } }
From source file:com.piaoyou.util.FileUtil.java
/** * This function is used to get the classpath of a reference of one class * First, this method tries to get the path from system properties * named "mvncore.context.path" (can be configured in web.xml). If it cannot * find this parameter, then it will tries to load from the ClassLoader * @todo FIXME: load from ClassLoader is not correct on Resin/Linux */// w w w . java 2 s . c o m public static String getServletClassesPath() { if (servletClassesPath == null) { String strPath = System.getProperty("mvncore.context.path"); if ((strPath != null) && (strPath.length() > 0)) { servletClassesPath = strPath; } else { ClassLoader classLoader = instance.getClass().getClassLoader(); URL url = classLoader.getResource("/"); if (url == null) { // not run on the Servlet environment servletClassesPath = "."; } else { servletClassesPath = url.getPath(); } } log.debug("servletClassesPath = " + servletClassesPath); if (servletClassesPath.endsWith(File.separator) == false) { servletClassesPath = servletClassesPath + File.separatorChar; //log.warn("servletClassesPath does not end with /: " + servletClassesPath); } } return servletClassesPath; }