List of usage examples for java.net URI getAuthority
public String getAuthority()
From source file:com.facebook.presto.hive.s3.PrestoS3FileSystem.java
/** * Helper function used to work around the fact that if you use an S3 bucket with an '_' that java.net.URI * behaves differently and sets the host value to null whereas S3 buckets without '_' have a properly * set host field. '_' is only allowed in S3 bucket names in us-east-1. * * @param uri The URI from which to extract a host value. * @return The host value where uri.getAuthority() is used when uri.getHost() returns null as long as no UserInfo is present. * @throws IllegalArgumentException If the bucket can not be determined from the URI. *///from ww w . j a va2 s . co m public static String getBucketName(URI uri) { if (uri.getHost() != null) { return uri.getHost(); } if (uri.getUserInfo() == null) { return uri.getAuthority(); } throw new IllegalArgumentException("Unable to determine S3 bucket from URI."); }
From source file:org.apache.sentry.core.common.utils.PathUtils.java
/** * URI is a a special case. For URI's, /a implies /a/b. * Therefore the test is "/a/b".startsWith("/a"); *///from ww w. j av a 2s . c o m public static boolean impliesURI(URI privilegeURI, URI requestURI) throws URISyntaxException { if (privilegeURI.getPath() == null || requestURI.getPath() == null) { return false; } // ensure that either both schemes are null or equal if (privilegeURI.getScheme() == null) { if (requestURI.getScheme() != null) { return false; } } else if (!privilegeURI.getScheme().equals(requestURI.getScheme())) { return false; } // request path does not contain relative parts /a/../b && // request path starts with privilege path && // authorities (nullable) are equal String requestPath = ensureEndsWithSeparator(requestURI.getPath()).replace("//", "/"); String privilegePath = ensureEndsWithSeparator(privilegeURI.getPath()).replace("//", "/"); if (requestURI.getPath().equals(requestURI.normalize().getPath()) && requestPath.startsWith(privilegePath) && Strings.nullToEmpty(privilegeURI.getAuthority()) .equals(Strings.nullToEmpty(requestURI.getAuthority()))) { return true; } return false; }
From source file:com.subgraph.vega.impl.scanner.handlers.DirParentCheck.java
private HttpUriRequest createRequest(IWebPath path) { final IWebPath parent = path.getParentPath(); String basePath = parent.getParentPath().getFullPath(); String newPath = basePath + "foo/" + path.getPathComponent(); final URI originalUri = path.getUri(); try {/* w w w . j av a 2s . c om*/ final URI newUri = new URI(originalUri.getScheme(), originalUri.getAuthority(), newPath, null, null); return new HttpGet(newUri); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:org.apache.hadoop.mapreduce.JobSubmitter.java
@SuppressWarnings("deprecation") private static void addMRFrameworkToDistributedCache(Configuration conf) throws IOException { String framework = conf.get(MRJobConfig.MAPREDUCE_APPLICATION_FRAMEWORK_PATH, ""); if (!framework.isEmpty()) { URI uri; try {/*from w ww .jav a 2 s . co m*/ uri = new URI(framework); } catch (URISyntaxException e) { throw new IllegalArgumentException("Unable to parse '" + framework + "' as a URI, check the setting for " + MRJobConfig.MAPREDUCE_APPLICATION_FRAMEWORK_PATH, e); } String linkedName = uri.getFragment(); // resolve any symlinks in the URI path so using a "current" symlink // to point to a specific version shows the specific version // in the distributed cache configuration FileSystem fs = FileSystem.get(uri, conf); Path frameworkPath = fs.makeQualified(new Path(uri.getScheme(), uri.getAuthority(), uri.getPath())); FileContext fc = FileContext.getFileContext(frameworkPath.toUri(), conf); frameworkPath = fc.resolvePath(frameworkPath); uri = frameworkPath.toUri(); try { uri = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, linkedName); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } DistributedCache.addCacheArchive(uri, conf); } }
From source file:org.dataconservancy.dcs.util.UriUtility.java
/** * Resolves the supplied {@code bag://} URI against a platform-specific base directory. This method is used to * resolve resources in a bag to a platform-specific {@code Path} used by the caller to access the content of the * resource.//from www. ja v a 2 s .com * <p> * Example usage: * Given a bag that contains a resource identified by the URI {@code bag://my-bag/data/bar}, and the bag has been * exploded into the directory {@code /tmp/foo/my-bag} (where the bag payload directory is located at * {@code /tmp/foo/my-bag/data}) then the base directory of the bag is {@code /tmp/foo}. If the caller wishes to * resolve the URI {@code bag://my-bag/data/bar}, they would invoke this method: * </p> * <pre> * Path result = UriUtility.resolveBagUri(Paths.get("/tmp/foo"), new URI("bag://my-bag/data/bar")); * assert Paths.get("/tmp/foo/my-bag/data/bar").equals(result); * </pre> * <p> * The base directory does not need to exist. This implementation will {@link Path#normalize() normalize} the * supplied directory. * </p> * <p> * The {@code bag://} URI is converted to a path by concatenating the authority portion of the URI with the path * portion. * </p> * <p> * If the supplied {@code bagUri} is <em>not</em> a URI with the {@code bag} scheme, an * {@code IllegalArgumentException} is thrown. * </p> * * @param baseDir the base directory that contains the bag * @param bagUri a URI identifying a resource in a bag * @return a platform-specific {@code Path}, used to access the contents of the resource identified by {@code bagUri} * @throws IllegalArgumentException if the supplied bagUri is null or empty, if {@code baseDir} is null, if * {@code bagUri} does not have scheme {@code bag} * @throws RuntimeException if the supplied base directory cannot be normalized */ public static Path resolveBagUri(Path baseDir, URI bagUri) { if (bagUri == null) { throw new IllegalArgumentException( String.format(ERR_RESOLVE_BAGURI + "bag uri was null.", "null", baseDir)); } if (!bagUri.getScheme().equals(BAG_URI_SCHEME)) { throw new IllegalArgumentException( String.format(ERR_RESOLVE_BAGURI + "bag uri had incorrect scheme.", bagUri, baseDir)); } if (baseDir == null) { throw new IllegalArgumentException( String.format(ERR_RESOLVE_BAGURI + "base directory was null", bagUri, "null")); } // normalize the base directory path Path originalDir = baseDir; baseDir = baseDir.normalize(); if (baseDir == null) { throw new RuntimeException(String.format(ERR_RESOLVE_BAGURI + "failed to normalize the base directory.", bagUri, originalDir)); } Path bagPath = Paths.get(bagUri.getAuthority(), bagUri.getPath()); return baseDir.resolve(bagPath); }
From source file:com.subgraph.vega.impl.scanner.handlers.DirIPSCheck.java
private HttpUriRequest createRequest(IPathState ps, String query) { final URI baseUri = ps.getPath().getUri(); try {// w w w . j a va2 s . c om final URI newUri = new URI(baseUri.getScheme(), baseUri.getAuthority(), baseUri.getPath(), query, null); return new HttpGet(newUri); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:com.microsoft.tfs.core.util.URIUtils.java
/** * <p>/*from w ww. j a v a 2 s .co m*/ * Ensures that the specified {@link URI}'s path component ends with a slash * character (<code>/</code>). * </p> * * <p> * {@link URI}s that will be resolved against should always have a trailing * slash in their path component. For more information, see Sun Java bug * 4666701 (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4666701). * </p> * * <p> * If the specified {@link URI} is opaque, it is returned. If the specified * {@link URI} is hierarchical and its path component already ends in a * slash, it is returned. Otherwise, a new {@link URI} is returned that is * identical to the specified {@link URI} except in its path component, * which will have a slash appended on. * </p> * * @param uri * a {@link URI} to check (must not be <code>null</code>) * @return a {@link URI} as described above (never <code>null</code>) */ public static URI ensurePathHasTrailingSlash(final URI uri) { Check.notNull(uri, "uri"); //$NON-NLS-1$ if (uri.isOpaque()) { return uri; } String path = uri.getPath(); if (path != null && path.endsWith("/")) //$NON-NLS-1$ { return uri; } if (path == null) { path = "/"; //$NON-NLS-1$ } else { path = path + "/"; //$NON-NLS-1$ } return newURI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(), uri.getFragment()); }
From source file:com.bazaarvoice.seo.sdk.util.BVUtilty.java
public static String removeBVQuery(String queryUrl) { final URI uri; try {/*from w w w .j av a 2s. c o m*/ uri = new URI(queryUrl); } catch (URISyntaxException e) { return queryUrl; } try { String newQuery = null; if (uri.getQuery() != null && uri.getQuery().length() > 0) { List<NameValuePair> newParameters = new ArrayList<NameValuePair>(); List<NameValuePair> parameters = URLEncodedUtils.parse(uri.getQuery(), Charset.forName("UTF-8")); List<String> bvParameters = Arrays.asList("bvrrp", "bvsyp", "bvqap", "bvpage"); for (NameValuePair parameter : parameters) { if (!bvParameters.contains(parameter.getName())) { newParameters.add(parameter); } } newQuery = newParameters.size() > 0 ? URLEncodedUtils.format(newParameters, Charset.forName("UTF-8")) : null; } return new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), newQuery, null).toString(); } catch (URISyntaxException e) { return queryUrl; } }
From source file:com.github.brandtg.pantopod.crawler.CrawlingEventHandler.java
private boolean isSameDomain(URI url, URI nextUrl) throws IOException { if (nextUrl.getAuthority() == null || nextUrl.getAuthority().equals(url.getAuthority())) { return true; }/*from w w w. ja v a 2 s .c o m*/ handleExternalDomain(url, nextUrl); return false; }
From source file:com.microsoft.tfs.core.util.URIUtils.java
/** * Ensures that the specified {@link URI} has any trailing slashes REMOVED. * VisualStudio uses server URIs that lack trailing slashes, this is for * compatibility. However, a path of only / will be maintained. * * @param uri/*from w w w.j a v a2 s .com*/ * a {@link URI} to check (must not be <code>null</code>) * @return a {@link URI} as described above (never <code>null</code>) */ public static URI removeTrailingSlash(final URI uri) { Check.notNull(uri, "uri"); //$NON-NLS-1$ if (uri.isOpaque()) { return uri; } String path = uri.getPath(); if (path == null) { path = "/"; //$NON-NLS-1$ } else if (!path.equals("/")) //$NON-NLS-1$ { while (path.endsWith("/")) //$NON-NLS-1$ { path = path.substring(0, path.length() - 1); } } return newURI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(), uri.getFragment()); }