List of usage examples for java.net URI getPath
public String getPath()
From source file:com.mgmtp.jfunk.web.util.DumpFileCreator.java
/** * Computes the best file to save the response to the current page. *//*from w ww . j av a2 s.co m*/ public File createDumpFile(final File dir, final String extension, final String urlString, final String additionalInfo) { URI uri = URI.create(urlString); String path = uri.getPath(); if (path == null) { log.warn("Cannot create dump file for URI: " + uri); return null; } String name = PATTERN_FIRST_LAST_SLASH.matcher(path).replaceAll("$1"); name = PATTERN_ILLEGAL_CHARS.matcher(name).replaceAll("_"); Key key = Key.get(dir.getPath(), extension); MutableInt counter = countersMap.get(key); if (counter == null) { counter = new MutableInt(); countersMap.put(key, counter); } int counterValue = counter.intValue(); counter.increment(); StringBuilder sb = new StringBuilder(); sb.append(String.format("%04d", counterValue)); sb.append('_'); sb.append(name); if (StringUtils.isNotBlank(additionalInfo)) { sb.append("_"); sb.append(additionalInfo); } sb.append("."); sb.append(extension); return new File(dir, sb.toString()); }
From source file:alfreso.hadoop.store.hadoop_store.store.HadoopDownload.java
private String generateDownloadLink(String filePath) { URI uri; String name = ""; try {// w w w.ja v a 2s . c o m uri = new URI(filePath); String[] segments = uri.getPath().split("/"); name = segments[segments.length - 1]; } catch (URISyntaxException e) { e.printStackTrace(); } //TODO: fix build set up and delete this return TEMP_DIR + name; /* * TODO: fix build set up and uncomment this if(HD.copyToLocal(filePath, (TEMP_DIR+name))) { return "<a href=\"" + filePath + "\">" + filePath + "</a>"; } return "ERROR - retrieval failed"; */ }
From source file:org.gradle.caching.http.internal.HttpBuildCache.java
public HttpBuildCache(URI root) { if (!root.getPath().endsWith("/")) { throw new IncompleteArgumentException("HTTP cache root URI must end with '/'"); }// w w w . ja v a 2s . co m this.root = root; this.safeUri = safeUri(root); this.httpClient = HttpClients.createDefault(); }
From source file:com.orange.clara.tool.service.RssService.java
public SyndImage generateImage(String imageUrl) { SyndImage image = new SyndImageImpl(); URI imageUri = URI.create(imageUrl); File imageFile = new File(imageUri.getPath()); image.setTitle(imageFile.getName() + " image"); image.setUrl(imageUrl);// www. ja v a2 s. co m image.setLink(imageUrl); return image; }
From source file:org.test.skeleton.controller.JsonMessageParser.java
private User getUserFromUri(String userUri) throws Exception { URI uri = new URI(userUri); Map<String, String> extractUriTemplateVariables = pathMatcher.extractUriTemplateVariables("/users/{id}", uri.getPath()); String idString = extractUriTemplateVariables.get("id"); Long id = Long.parseLong(idString); return userDao.findOne(id); }
From source file:sample.mvc.JsonMessageParser.java
private User getUserFromUri(String userUri) throws Exception { URI uri = new URI(userUri); Map<String, String> extractUriTemplateVariables = pathMatcher.extractUriTemplateVariables("/users/{id}", uri.getPath()); String idString = extractUriTemplateVariables.get("id"); Long id = Long.parseLong(idString); return userRepository.findOne(id); }
From source file:AIR.Common.Web.FileFtpHandler.java
/** * Makes FTP call to the provided URI and retrieves contents * /*from ww w . j a v a 2 s . c o m*/ * @param uri * @return ByteArrayInputStream * @throws FtpResourceException */ public static byte[] getBytes(URI uri) throws FtpResourceException { try { FTPClient ftp = new FTPClient(); String[] credentialsAndHost = uri.getAuthority().split("@"); String host = credentialsAndHost[1]; String[] credentials = credentialsAndHost[0].split(":"); ftp.connect(host); ftp.enterLocalPassiveMode(); if (!ftp.login(credentials[0], credentials[1])) { ftp.logout(); ftp.disconnect(); throw new RuntimeException("FTP Authentication Failure"); } int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.logout(); ftp.disconnect(); throw new RuntimeException("FTP No reponse from server"); } ftp.setFileType(FTPClient.BINARY_FILE_TYPE); ByteArrayOutputStream output = new ByteArrayOutputStream(); ftp.retrieveFile(uri.getPath(), output); output.close(); ftp.logout(); ftp.disconnect(); return output.toByteArray(); } catch (IOException ex) { throw new FtpResourceException(ex); } }
From source file:com.sangupta.jerry.oauth.OAuthUtils.java
/** * Return the signing base URL that is appended after the HTTP VERB in OAuth * header./*w ww . j av a 2 s . co m*/ * * @param uri * the {@link URI} instance from which the signing base is * extracted * * @return the extracted signing base from the {@link URI} instance */ public static String getSigningBaseURL(URI uri) { if (uri == null) { throw new IllegalArgumentException("URI cannot be null"); } StringBuilder builder = new StringBuilder(); builder.append(uri.getScheme().toLowerCase()); builder.append("://"); builder.append(uri.getHost().toLowerCase()); int port = uri.getPort(); if (!(port == 80 || port == -1)) { builder.append(':'); builder.append(String.valueOf(port)); } builder.append(uri.getPath()); return builder.toString(); }
From source file:io.druid.segment.loading.LocalDataSegmentPusher.java
@Override public Map<String, Object> makeLoadSpec(URI finalIndexZipFilePath) { return ImmutableMap.<String, Object>of("type", "local", "path", finalIndexZipFilePath.getPath()); }
From source file:de.tudarmstadt.ukp.dkpro.keyphrases.bookindexing.evaluation.phrasematch.LineReader.java
/** * @param jcas//from w w w. j a v a 2s .c o m * @return the document basename from the parsed document-URI-path. * @throws AnalysisEngineProcessException */ private String getDocumentBaseName(JCas jcas) throws AnalysisEngineProcessException { try { URI uri = new URI(DocumentMetaData.get(jcas).getDocumentUri()); return FilenameUtils.getBaseName(uri.getPath()); } catch (URISyntaxException e) { throw new AnalysisEngineProcessException(e); } }