List of usage examples for java.net URL getPath
public String getPath()
From source file:gate.corpora.twitter.Population.java
private static Document newDocument(URL url, int counter, int digits) throws ResourceInstantiationException { Document document = Factory.newDocument(""); String code = StringUtils.leftPad(Integer.toString(counter), digits, '0'); String name = StringUtils.stripToEmpty(StringUtils.substring(url.getPath(), 1)) + "_" + code; document.setName(name);//from w w w . j a v a 2 s .com document.setSourceUrl(url); document.getFeatures().put(Document.DOCUMENT_MIME_TYPE_PARAMETER_NAME, TweetUtils.MIME_TYPE); document.getFeatures().put("gate.SourceURL", url.toString()); return document; }
From source file:io.Tools.java
public static AlgoParameters generateModifiedAlgoParametersForTestWithTestFolders() throws ParsingConfigFileException, IOException { URL url = BiojavaReaderFromPDBFolderTest.class.getClassLoader().getResource("ultimate.xml"); AlgoParameters algoParameters = CommandLineTools.generateModifiedAlgoParameters(url.getPath(), EnumMyReaderBiojava.BioJava_MMCIFF); algoParameters.setPATH_TO_REMEDIATED_PDB_MMCIF_FOLDER(testPDBFolder); algoParameters.setPATH_TO_CHEMCOMP_FOLDER(testChemcompFolder); algoParameters.setPATH_TO_RESULT_FILES(testChemcompFolder); return algoParameters; }
From source file:com.ejisto.util.IOUtils.java
private static List<WebApplicationDescriptorElement> getClasspathEntries(String basePath, URL[] baseUrls) { File base = new File(basePath); List<WebApplicationDescriptorElement> elements = new ArrayList<>(); for (URL url : baseUrls) { elements.add(new WebApplicationDescriptorElement(url.getPath())); }/*from w ww. jav a 2s . co m*/ elements.addAll(toWebApplicationDescriptorElement(getAllFiles(base, jarExtension))); return elements; }
From source file:com.zxy.commons.email.MailMessageUtils.java
/** * smtp??/*from ww w .j a v a 2s . co m*/ * * @param subject subject * @param htmlBody htmlBody * @param properties properties * @param from from * @param toList toList * @param ccList ccList * @param bccList bccList * @param embedUrls * @throws EmailException EmailException */ @SuppressWarnings({ "PMD.AvoidInstantiatingObjectsInLoops", "PMD.UseStringBufferForStringAppends" }) public static void sendMail(String subject, String htmlBody, Map<String, String> properties, String from, List<String> toList, List<String> ccList, List<String> bccList, Map<String, URL> embedUrls) throws EmailException { HtmlEmail htmlEmail = getEmail(); // from? if (!Strings.isNullOrEmpty(from)) { Address fromMailbox = parseMailbox(from); if (fromMailbox != null && StringUtils.isNotBlank(from)) { htmlEmail.setFrom(fromMailbox.getAddress(), fromMailbox.getName()); } } // to? if (toList != null && !toList.isEmpty()) { for (String to : toList) { if (StringUtils.isNotBlank(to)) { Address toMailbox = parseMailbox(to); htmlEmail.addTo(toMailbox.getAddress(), toMailbox.getName()); } } } // cc? if (ccList != null && !ccList.isEmpty()) { for (String cc : ccList) { if (StringUtils.isNotBlank(cc)) { Address ccMailbox = parseMailbox(cc); htmlEmail.addCc(ccMailbox.getAddress(), ccMailbox.getName()); } } } // bcc? if (bccList != null && !bccList.isEmpty()) { for (String bcc : bccList) { if (StringUtils.isNotBlank(bcc)) { Address bccMailbox = parseMailbox(bcc); htmlEmail.addBcc(bccMailbox.getAddress(), bccMailbox.getName()); } } } // htmlEmail.setSubject(subject); htmlEmail.setHtmlMsg(htmlBody); htmlEmail.setSentDate(new Date()); // if (properties != null) { htmlEmail.setHeaders(properties); } // if (embedUrls != null && !embedUrls.isEmpty()) { for (Map.Entry<String, URL> entry : embedUrls.entrySet()) { String cid = entry.getKey(); URL url = entry.getValue(); String fileName = StringUtils.substringAfterLast(url.getPath(), "/"); if (StringUtils.isBlank(fileName)) { fileName = cid; } else { fileName += IdUtils.genStringId(); } htmlEmail.embed(new URLDataSource(url), fileName, cid); } } htmlEmail.send(); }
From source file:com.dmsl.anyplace.utils.NetworkUtils.java
public static String encodeURL(String urlStr) throws URISyntaxException, MalformedURLException { URL url = new URL(urlStr); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); url = uri.toURL();/*w w w .java 2 s. c o m*/ return url.toString(); }
From source file:com.yahoo.storm.yarn.StormOnYarn.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. * /* w w w . ja va2s . c o m*/ * @param my_class the class to find. * @return a jar file that contains the class, or null. * @throws IOException on any error */ public static String findContainingJar(Class<?> my_class) throws IOException { ClassLoader loader = my_class.getClassLoader(); String class_file = my_class.getName().replaceAll("\\.", "/") + ".class"; for (Enumeration<URL> itr = loader.getResources(class_file); itr.hasMoreElements();) { 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("!.*$", ""); } } throw new IOException("Fail to locat a JAR for class: " + my_class.getName()); }
From source file:com.centeractive.ws.builder.ServiceComplianceTest.java
public static String getExpectedMessage(int testServiceId, String bindingName, String operationName, MessageType msg) {/* w w w .j a v a 2 s . com*/ String serviceFolderPath = getTestServiceFolderPath(testServiceId); String messageFolderPath = String.format("%s/operations/%s", serviceFolderPath, bindingName); String fileName = operationName + "." + (MessageType.REQUEST.equals(msg) ? "request" : "response") + ".xml"; URL fileUrl = ResourceUtils.getResourceWithAbsolutePackagePath(messageFolderPath, fileName); File file = null; try { file = new File(fileUrl.toURI()); } catch (URISyntaxException e) { file = new File(fileUrl.getPath()); } try { return FileUtils.readFileToString(file); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.seajas.search.utilities.tags.URLTag.java
/** * Protect a given URL by starring out the password-portion. * /* w w w .j a va 2s. c o m*/ * @param url * @return String */ public static String protectUrl(final String url) { try { URL actualUrl = new URL(url); return actualUrl.getProtocol() + "://" + (StringUtils.isEmpty(actualUrl.getUserInfo()) ? "" : "****@") + actualUrl.getHost() + (actualUrl.getPort() == -1 ? "" : ':' + actualUrl.getPort()) + actualUrl.getPath() + (StringUtils.isEmpty(actualUrl.getQuery()) ? "" : '?' + actualUrl.getQuery()); } catch (MalformedURLException e) { return url; } }
From source file:com.github.wolf480pl.mias4j.util.AbstractTransformingClassLoader.java
public static URL guessCodeSourceURL(String resourcePath, URL resourceURL) { // FIXME: Find a better way to do this @SuppressWarnings("restriction") String escaped = sun.net.www.ParseUtil.encodePath(resourcePath, false); String path = resourceURL.getPath(); if (!path.endsWith(escaped)) { // Umm... whadda we do now? Maybe let's fallback to full resource URL. LOG.warn("Resource URL path \"" + path + "\" doesn't end with escaped resource path \"" + escaped + "\" for resource \"" + resourcePath + "\""); return resourceURL; }//from w ww . j a v a 2 s . c o m path = path.substring(0, path.length() - escaped.length()); if (path.endsWith("!/")) { // JAR path = path.substring(0, path.length() - 2); } try { URI uri = resourceURL.toURI(); return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery(), uri.getFragment()).toURL(); } catch (MalformedURLException | URISyntaxException e) { // Umm... whadda we do now? Maybe let's fallback to full resource URL. LOG.warn("Couldn't assemble CodeSource URL with modified path", e); return resourceURL; } }
From source file:info.extensiblecatalog.OAIToolkit.utils.ConfigUtil.java
public static PropertiesConfiguration load(String configFileName) throws Exception { prglog.info("[PRG] ConfigUtil::load(" + configFileName + ")"); ClassLoader cloader = ConfigUtil.class.getClassLoader(); URL configFile = cloader.getResource(configFileName); if (null == configFile) { File f = new File(configFileName); prglog.info("[PRG] load from file: " + f.getAbsolutePath()); configFile = new URL("file", "", f.getAbsolutePath()); }/* w w w. jav a2s. c o m*/ prglog.info("config file: " + configFile.getPath()); //System.out.println("The config file is " + configFile); //System.out.println("The config file name is " + configFileName); if (!(new File(configFile.getPath()).exists())) { prglog.error("[PRG] Inexistent configuration file: " + configFileName); throw new Exception("Inexistent configuration file: " + configFileName); } BufferedReader re = new BufferedReader(new FileReader(configFile.getPath())); /* String tmpfile = "tmpfile.txt"; // Create new file File temp = new File(tmpfile); boolean success = temp.createNewFile(); if (success) { System.out.println("Its success"); //File did not exist and was created } else { System.out.println("File already exists"); //File already exists } if (!temp.exists()) throw new IllegalArgumentException("no such file or directory: " + temp); if (!temp.canWrite()) throw new IllegalArgumentException("Write protected: " + temp); System.out.println("Temporary file created. File is " + temp); //System.out.println("Temporary file created. Path is " + temp.getPath()); BufferedWriter out = new BufferedWriter(new FileWriter(temp)); while(true) { String s = re.readLine(); //System.out.println(s); if(s!=null) { s = s.replaceAll("\\\\", "/"); //System.out.println(s); out.write(s + System.getProperty("line.separator")); out.flush(); } else break; } out.close(); */ try { //PropertiesConfiguration prop = new PropertiesConfiguration(temp); PropertiesConfiguration prop = new PropertiesConfiguration(configFile.getPath()); prglog.info("[PRG] successful ConfigUtil::load"); //temp.deleteOnExit(); /*boolean dsuccess = temp.delete(); if (!dsuccess) throw new IllegalArgumentException("Delete: deletion failed");*/ return prop; } catch (ConfigurationException e) { prglog.error("[PRG] Unable to load properties from configuration file: " + configFileName + ". " + e.getMessage()); throw new Exception( "Unable to load properties from configuration file: " + configFileName + ". " + e.getMessage()); } }