List of usage examples for java.net URI getPath
public String getPath()
From source file:com.vmware.thinapp.common.util.AfUtil.java
/** * Given a URI, return the last uri token. * * @param uri Last token/*from w w w . jav a2 s .co m*/ * @return */ public static String extractLastURIToken(URI uri) { if (uri == null || !StringUtils.hasLength(uri.getPath())) { return null; } String tokens[] = uri.getPath().split("/"); return tokens[tokens.length - 1]; }
From source file:com.simiacryptus.util.Util.java
/** * Cache file file./* ww w . j a va 2 s.co m*/ * * @param url the url * @return the file * @throws IOException the io exception * @throws NoSuchAlgorithmException the no such algorithm exception * @throws KeyStoreException the key store exception * @throws KeyManagementException the key management exception */ public static File cacheFile(@javax.annotation.Nonnull final URI url) throws IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { return com.simiacryptus.util.Util.cacheFile(url.toString(), new File(url.getPath()).getName()); }
From source file:com.simiacryptus.util.Util.java
/** * Cache input stream.// w w w.j a va 2 s.c o m * * @param url the url * @return the input stream * @throws IOException the io exception * @throws NoSuchAlgorithmException the no such algorithm exception * @throws KeyStoreException the key store exception * @throws KeyManagementException the key management exception */ public static InputStream cacheStream(@javax.annotation.Nonnull final URI url) throws IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { return com.simiacryptus.util.Util.cacheStream(url.toString(), new File(url.getPath()).getName()); }
From source file:org.esigate.DriverFactory.java
/** * Selects the Driver instance for this request based on the mappings declared in the configuration. * //w w w . ja v a 2 s. c o m * @param request * the incoming request * * @return a {@link MatchedRequest} containing the {@link Driver} instance and the relative URI * * @throws HttpErrorPage * if no instance was found for this request */ static MatchedRequest selectProvider(IncomingRequest request) throws HttpErrorPage { URI requestURI = UriUtils.createURI(request.getRequestLine().getUri()); String host = UriUtils.extractHost(requestURI).toHostString(); Header hostHeader = request.getFirstHeader(HttpHeaders.HOST); if (hostHeader != null) { host = hostHeader.getValue(); } String scheme = requestURI.getScheme(); String relativeUri = requestURI.getPath(); String contextPath = request.getContextPath(); if (!StringUtils.isEmpty(contextPath) && relativeUri.startsWith(contextPath)) { relativeUri = relativeUri.substring(contextPath.length()); } Driver driver = null; UriMapping uriMapping = null; for (UriMapping mapping : instances.getUrimappings().keySet()) { if (mapping.matches(scheme, host, relativeUri)) { driver = getInstance(instances.getUrimappings().get(mapping)); uriMapping = mapping; break; } } if (driver == null) { throw new HttpErrorPage(HttpStatus.SC_NOT_FOUND, "Not found", "No mapping defined for this URI."); } if (driver.getConfiguration().isStripMappingPath()) { relativeUri = DriverFactory.stripMappingPath(relativeUri, uriMapping); } MatchedRequest context = new MatchedRequest(driver, relativeUri); LOG.debug("Selected {} for scheme:{} host:{} relUrl:{}", driver, scheme, host, relativeUri); return context; }
From source file:fr.afcepf.atod.wine.data.parser.XmlParser.java
private static String getResourcePath() { try {//from ww w .j av a 2s.com URI resourcePathFile = System.class.getResource("/RESOURCE_PATH").toURI(); String resourcePath = Files.readAllLines(Paths.get(resourcePathFile)).get(0); URI rootURI = new File("").toURI(); URI resourceURI = new File(resourcePath).toURI(); URI relativeResourceURI = rootURI.relativize(resourceURI); return relativeResourceURI.getPath(); } catch (Exception e) { return null; } }
From source file:com.microsoft.alm.common.utils.UrlHelper.java
public static String getHttpsGitUrlFromSshUrl(final String sshGitRemoteUrl) { if (isSshGitRemoteUrl(sshGitRemoteUrl)) { final URI sshUrl; if (!StringUtils.startsWithIgnoreCase(sshGitRemoteUrl, "ssh://")) { sshUrl = UrlHelper.createUri("ssh://" + sshGitRemoteUrl); } else {//www . ja v a 2 s.c om sshUrl = UrlHelper.createUri(sshGitRemoteUrl); } final String host = sshUrl.getHost(); final String path = sshUrl.getPath(); final URI httpsUrl = UrlHelper.createUri("https://" + host + path); return httpsUrl.toString(); } return null; }
From source file:com.twitter.distributedlog.DLMTestUtil.java
static BKLogPartitionWriteHandlerAndClients createNewBKDLM(DistributedLogConfiguration conf, String logName, int zkPort) throws Exception { URI uri = createDLMURI(zkPort, "/" + logName); ZooKeeperClientBuilder zkcBuilder = TestZooKeeperClientBuilder.newBuilder(conf) .name(String.format("dlzk:%s:handler_dedicated", logName)).uri(uri); ZooKeeperClient zkClient = zkcBuilder.build(); try {//from w w w . jav a2s . com zkClient.get().create(uri.getPath(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException nee) { // ignore } // resolve uri BKDLConfig bkdlConfig = BKDLConfig.resolveDLConfig(zkClient, uri); BKDLConfig.propagateConfiguration(bkdlConfig, conf); BookKeeperClientBuilder bkcBuilder = BookKeeperClientBuilder.newBuilder().dlConfig(conf) .name(String.format("bk:%s:handler_dedicated", logName)) .zkServers(bkdlConfig.getBkZkServersForWriter()).ledgersPath(bkdlConfig.getBkLedgersPath()) .statsLogger(NullStatsLogger.INSTANCE); BKDistributedLogManager bkdlm = new BKDistributedLogManager(logName, conf, uri, zkcBuilder, zkcBuilder, zkClient, zkClient, bkcBuilder, bkcBuilder, new SettableFeatureProvider("", 0), PermitLimiter.NULL_PERMIT_LIMITER, NullStatsLogger.INSTANCE); BKLogWriteHandler writeHandler = bkdlm.createWriteHandler(true); return new BKLogPartitionWriteHandlerAndClients(writeHandler, zkClient, bkcBuilder.build()); }
From source file:com.sworddance.util.UriFactoryImpl.java
/** * @param httpUri//from w w w.java 2 s . c o m * @return root URI */ public static URI getRootDirectory(URI httpUri) { String path = httpUri.getPath(); URI base = httpUri.resolve(substringBeforeLast(path, PATH_SEPARATOR) + PATH_SEPARATOR); return base; }
From source file:com.net.cookie.HttpCookie.java
/** * Returns true if {@code cookie} should be sent to or accepted from {@code uri} with respect * to the cookie's path. Cookies match by directory prefix: URI "/foo" matches cookies "/foo", * "/foo/" and "/foo/bar", but not "/" or "/foobar". */// w w w . j a v a 2s .c om static boolean pathMatches(HttpCookie cookie, URI uri) { String uriPath = matchablePath(uri.getPath()); String cookiePath = matchablePath(cookie.getPath()); return uriPath.startsWith(cookiePath); }
From source file:com.terremark.handlers.CloudApiAuthenticationHandler.java
/** * Builds a formatted string for the URI and the query string. * * @param request Client request.//www . j a v a2s .c om * @return Formatted URI and query arguments. */ private static String getCanonicalizedResource(final ClientRequest request) { final Map<String, String> queryMap = new TreeMap<String, String>(); final URI uri = request.getURI(); final String query = uri.getQuery(); if (query != null && query.length() > 0) { final String[] parts = query.split("&"); for (final String part : parts) { final String[] nameValue = part.split("="); if (nameValue.length == 2) { queryMap.put(nameValue[0].toLowerCase(), nameValue[1]); } } } final StringBuilder builder = new StringBuilder(); builder.append(uri.getPath().toLowerCase()).append('\n'); for (final Map.Entry<String, String> entry : queryMap.entrySet()) { builder.append(entry.getKey()).append(':').append(entry.getValue()).append('\n'); } return builder.toString(); }