List of usage examples for java.net URI getAuthority
public String getAuthority()
From source file:org.apache.hadoop.hive.ql.parse.EximUtil.java
public static String relativeToAbsolutePath(HiveConf conf, String location) throws SemanticException { try {//w w w . j a va2 s . com boolean testMode = conf.getBoolVar(HiveConf.ConfVars.HIVETESTMODE); if (testMode) { URI uri = new Path(location).toUri(); FileSystem fs = FileSystem.get(uri, conf); String scheme = fs.getScheme(); String authority = uri.getAuthority(); String path = uri.getPath(); if (!path.startsWith("/")) { path = (new Path(System.getProperty("test.tmp.dir"), path)).toUri().getPath(); } try { uri = new URI(scheme, authority, path, null, null); } catch (URISyntaxException e) { throw new SemanticException(ErrorMsg.INVALID_PATH.getMsg(), e); } return uri.toString(); } else { // no-op for non-test mode for now return location; } } catch (IOException e) { throw new SemanticException(ErrorMsg.IO_ERROR.getMsg() + ": " + e.getMessage(), e); } }
From source file:org.apache.distributedlog.impl.BKNamespaceDriver.java
/** * Extract zk servers fro dl <i>namespace</i>. * * @param uri dl namespace/* w ww . j av a 2 s . com*/ * @return zk servers */ public static String getZKServersFromDLUri(URI uri) { return uri.getAuthority().replace(";", ","); }
From source file:com.microsoft.alm.common.utils.UrlHelper.java
public static boolean haveSameAuthority(final URI remoteUrl1, final URI remoteUrl2) { if (remoteUrl1 != null && remoteUrl2 != null) { return StringUtils.equalsIgnoreCase(remoteUrl1.getAuthority(), remoteUrl2.getAuthority()); }//from ww w . j a va 2 s . com return false; }
From source file:org.apache.hadoop.hive.ql.parse.EximUtil.java
/** * Initialize the URI where the exported data collection is * to created for export, or is present for import *//*w w w .j av a 2s . c o m*/ public static URI getValidatedURI(HiveConf conf, String dcPath) throws SemanticException { try { boolean testMode = conf.getBoolVar(HiveConf.ConfVars.HIVETESTMODE); URI uri = new Path(dcPath).toUri(); FileSystem fs = FileSystem.get(uri, conf); // Get scheme from FileSystem String scheme = fs.getScheme(); String authority = uri.getAuthority(); String path = uri.getPath(); LOG.info("Path before norm :" + path); // generate absolute path relative to home directory if (!path.startsWith("/")) { if (testMode) { path = (new Path(System.getProperty("test.tmp.dir"), path)).toUri().getPath(); } else { path = (new Path(new Path("/user/" + System.getProperty("user.name")), path)).toUri().getPath(); } } // if scheme is specified but not authority then use the default authority if (StringUtils.isEmpty(authority)) { URI defaultURI = FileSystem.get(conf).getUri(); authority = defaultURI.getAuthority(); } LOG.info("Scheme:" + scheme + ", authority:" + authority + ", path:" + path); Collection<String> eximSchemes = conf .getStringCollection(HiveConf.ConfVars.HIVE_EXIM_URI_SCHEME_WL.varname); if (!eximSchemes.contains(scheme)) { throw new SemanticException( ErrorMsg.INVALID_PATH.getMsg("only the following file systems accepted for export/import : " + conf.get(HiveConf.ConfVars.HIVE_EXIM_URI_SCHEME_WL.varname))); } try { return new URI(scheme, authority, path, null, null); } catch (URISyntaxException e) { throw new SemanticException(ErrorMsg.INVALID_PATH.getMsg(), e); } } catch (IOException e) { throw new SemanticException(ErrorMsg.IO_ERROR.getMsg() + ": " + e.getMessage(), e); } }
From source file:UriUtils.java
/** * Resolves the specified URI, and returns the file represented by the URI. * * @param uri The URI for which to return an absolute path. * @return The {@link File} instance represented by the specified URI. * @throws IllegalArgumentException <ul><li>The URI cannot be null.</li><li>Wrong URI scheme for path resolution; * only file:// URIs are supported.</li></ul> *//* w w w . ja v a 2 s. c o m*/ public static File getFile(URI uri) throws IllegalArgumentException { if (uri == null) throw new IllegalArgumentException("The URI cannot be null."); if (!"file".equals(uri.getScheme())) throw new IllegalArgumentException("Wrong URI scheme for path resolution, expected \"file\" " + "and got \"" + uri.getScheme() + "\""); // Workaround for the following bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5086147 // Remove (or add, take your pick...) extra slashes after the scheme part. if (uri.getAuthority() != null) try { uri = new URI(uri.toString().replace("file://", "file:/")); } catch (URISyntaxException e) { throw new IllegalArgumentException( "The specified URI contains an authority, but could not be " + "normalized.", e); } return new File(uri); }
From source file:com.limegroup.gnutella.licenses.LicenseFactoryImpl.java
/** Gets a CC license URI from the given license string. */ private static URI getCCLicenseURI(String license) { license = license.toLowerCase(Locale.US); // find where the URL should begin. int verifyAt = license.indexOf(CCConstants.URL_INDICATOR); if (verifyAt == -1) return null; int urlStart = verifyAt + CCConstants.URL_INDICATOR.length(); if (urlStart >= license.length()) return null; String url = license.substring(urlStart).trim(); URI uri = null; try {//from w w w . j av a 2 s . co m uri = URIUtils.toURI(url); // Make sure the scheme is HTTP. String scheme = uri.getScheme(); if (scheme == null || !scheme.equalsIgnoreCase("http")) throw new URISyntaxException(uri.toString(), "Invalid scheme: " + scheme); // Make sure the scheme has some authority. String authority = uri.getAuthority(); if (authority == null || authority.equals("") || authority.indexOf(' ') != -1) throw new URISyntaxException(uri.toString(), "Invalid authority: " + authority); } catch (URISyntaxException e) { //URIUtils.error(e); uri = null; LOG.error("Unable to create URI", e); } return uri; }
From source file:com.buaa.cfs.utils.SecurityUtil.java
/** * create the service name for a Delegation token * * @param uri of the service//from w w w. ja v a 2 s . com * @param defPort is used if the uri lacks a port * * @return the token service, or null if no authority * * @see #buildTokenService(InetSocketAddress) */ public static String buildDTServiceName(URI uri, int defPort) { String authority = uri.getAuthority(); if (authority == null) { return null; } InetSocketAddress addr = NetUtils.createSocketAddr(authority, defPort); return buildTokenService(addr).toString(); }
From source file:gobblin.runtime.api.TopologySpec.java
/** Creates a builder for the TopologySpec based on values in a topology properties config. */ public static TopologySpec.Builder builder(URI catalogURI, Properties topologyProps) { String name = topologyProps.getProperty(ConfigurationKeys.TOPOLOGY_NAME_KEY); String group = topologyProps.getProperty(ConfigurationKeys.TOPOLOGY_GROUP_KEY, "default"); try {//from w w w . j a va 2 s . c om URI topologyURI = new URI(catalogURI.getScheme(), catalogURI.getAuthority(), "/" + group + "/" + name, null); TopologySpec.Builder builder = new TopologySpec.Builder(topologyURI) .withConfigAsProperties(topologyProps); String descr = topologyProps.getProperty(ConfigurationKeys.TOPOLOGY_DESCRIPTION_KEY, null); if (null != descr) { builder = builder.withDescription(descr); } return builder; } catch (URISyntaxException e) { throw new RuntimeException("Unable to create a TopologySpec URI: " + e, e); } }
From source file:org.apache.hadoop.hdfs.qjournal.client.QuorumJournalManager.java
private static List<InetSocketAddress> getLoggerAddresses(URI uri) throws IOException { String authority = uri.getAuthority(); Preconditions.checkArgument(authority != null && !authority.isEmpty(), "URI has no authority: " + uri); String[] parts = StringUtils.split(authority, ';'); for (int i = 0; i < parts.length; i++) { parts[i] = parts[i].trim();//from www.j av a2 s .c o m } if (parts.length % 2 == 0) { LOG.warn("Quorum journal URI '" + uri + "' has an even number " + "of Journal Nodes specified. This is not recommended!"); } List<InetSocketAddress> addrs = Lists.newArrayList(); for (String addr : parts) { addrs.add(NetUtils.createSocketAddr(addr, DFSConfigKeys.DFS_JOURNALNODE_RPC_PORT_DEFAULT)); } return addrs; }
From source file:RawParascaleFileSystem.java
/** * Parsing the an uri and extract the virtualFS and host name from the * authority part of the {@link URI}. If no authority is set the default * authority of the filesystem will be returned * * @param aUri uri to extract the authority from * * @return An array of strings where the first element is the Parascale * virtualFS and the second is the host of the NFS mount *///from w ww . java2 s . com static String[] parseAuthority(final URI aUri) { final String authority = aUri.getAuthority(); final int indexOf = authority.indexOf('@'); // if @ is not present assume default if (indexOf == -1) { return new String[] { DEFAULT_FILESYSTEM, authority }; } // virtualFs, controlNode return new String[] { authority.substring(0, indexOf), authority.substring(indexOf + 1, authority.length()) }; }