List of usage examples for java.net URI getAuthority
public String getAuthority()
From source file:com.buaa.cfs.fs.Path.java
/** Resolve a child path against a parent path. */ public Path(Path parent, Path child) { // Add a slash to parent's path so resolution is compatible with URI's URI parentUri = parent.uri; String parentPath = parentUri.getPath(); if (!(parentPath.equals("/") || parentPath.isEmpty())) { try {// ww w .j a va2 s.c o m parentUri = new URI(parentUri.getScheme(), parentUri.getAuthority(), parentUri.getPath() + "/", null, parentUri.getFragment()); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } } URI resolved = parentUri.resolve(child.uri); initialize(resolved.getScheme(), resolved.getAuthority(), resolved.getPath(), resolved.getFragment()); }
From source file:org.apache.hadoop.fs.Path.java
/** * Returns a qualified path object.// www . j a v a 2s. co m * * @param defaultUri if this path is missing the scheme or authority * components, borrow them from this URI * @param workingDir if this path isn't absolute, treat it as relative to this * working directory * @return this path if it contains a scheme and authority and is absolute, or * a new path that includes a path and authority and is fully qualified */ @InterfaceAudience.LimitedPrivate({ "HDFS", "MapReduce" }) public Path makeQualified(URI defaultUri, Path workingDir) { Path path = this; if (!isAbsolute()) { path = new Path(workingDir, this); } URI pathUri = path.toUri(); String scheme = pathUri.getScheme(); String authority = pathUri.getAuthority(); String fragment = pathUri.getFragment(); if (scheme != null && (authority != null || defaultUri.getAuthority() == null)) return path; if (scheme == null) { scheme = defaultUri.getScheme(); } if (authority == null) { authority = defaultUri.getAuthority(); if (authority == null) { authority = ""; } } URI newUri = null; try { newUri = new URI(scheme, authority, normalizePath(scheme, pathUri.getPath()), null, fragment); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } return new Path(newUri); }
From source file:org.apache.camel.component.kestrel.KestrelComponent.java
@SuppressWarnings("unchecked") protected KestrelEndpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception { // Copy the configuration as each endpoint can override defaults KestrelConfiguration config = getConfiguration().copy(); // Parse the URI, expected to be in one of the following formats: // 1. Use the base KestrelConfiguration for host addresses: // kestrel://queue[?parameters] // kestrel:///queue[?parameters] // 2. Override the host, but use the default port: // kestrel://host/queue[?parameters] // 3. Override the host and port: // kestrel://host:port/queue[?parameters] // 4. Supply a list of host addresses: // kestrel://host[:port],host[:port]/queue[?parameters] URI u = new URI(uri); String queue;// w ww . java2 s . c o m String[] addresses = null; if (u.getPath() == null || "".equals(u.getPath())) { // This would be the case when they haven't specified any explicit // address(es), and the queue ends up in the "authority" portion of // the URI. For example: // kestrel://queue[?parameters] queue = u.getAuthority(); } else if (u.getAuthority() == null || "".equals(u.getAuthority())) { // The "path" was present without an authority, such as: // kestrel:///queue[?parameters] queue = u.getPath(); } else { // Both "path" and "authority" were present in the URI, which // means both address(es) and the queue were specified, i.e.: // kestrel://host/queue[?parameters] // kestrel://host:port/queue[?parameters] // kestrel://host[:port],host[:port]/queue[?parameters] addresses = u.getAuthority().split(","); queue = u.getPath(); } // Trim off any slash(es), i.e. "/queue/" -> "queue" while (queue.startsWith("/")) { queue = queue.substring(1); } while (queue.endsWith("/")) { queue = queue.substring(0, queue.length() - 1); } if ("".equals(queue)) { // This would be the case if the URI didn't include a path, or if // the path was just "/" or something...throw an exception. throw new IllegalArgumentException("Queue not specified in endpoint URI: " + uri); } if (addresses != null && addresses.length > 0) { // Override the addresses on the copied config config.setAddresses(addresses); } else { // Explicit address(es) weren't specified on the URI, which is // no problem...just default the addresses to whatever was set on // the base KestrelConfiguration. And since we've already copied // the config, there's nothing else we need to do there. But let's // make sure the addresses field was indeed set on the base config. if (config.getAddresses() == null) { throw new IllegalArgumentException("Addresses not set in base configuration or endpoint: " + uri); } } LOG.info("Creating endpoint for queue \"" + queue + "\" on " + config.getAddressesAsString() + ", parameters=" + parameters); // Finally, override config with any supplied URI parameters setProperties(config, parameters); // Create the endpoint for the given queue with the config we built return new KestrelEndpoint(uri, this, config, queue); }
From source file:org.apache.distributedlog.service.DistributedLogClientBuilder.java
/** * URI to access proxy services./* ww w. java2s.c o m*/ * * <p>Assuming the write proxies are announced under `.write_proxy` of the provided namespace uri. * The builder will convert the dl uri (e.g. distributedlog://{zkserver}/path/to/namespace) to * zookeeper serverset based finagle name str (`zk!{zkserver}!/path/to/namespace/.write_proxy`) * * @param uri namespace uri to access the serverset of write proxies * @return distributedlog builder */ public DistributedLogClientBuilder uri(URI uri) { DistributedLogClientBuilder newBuilder = newBuilder(this); String zkServers = uri.getAuthority().replace(";", ","); String[] zkServerList = StringUtils.split(zkServers, ','); String finagleNameStr = String.format("zk!%s!%s/.write_proxy", zkServerList[random.nextInt(zkServerList.length)], // zk server uri.getPath()); newBuilder.routingServiceBuilder = RoutingUtils.buildRoutingService(finagleNameStr); newBuilder.enableRegionStats = false; return newBuilder; }
From source file:org.apache.accumulo.server.fs.VolumeManagerImpl.java
@Override public Path matchingFileSystem(Path source, String[] options) { try {/*from ww w .j a va 2 s . c om*/ if (ViewFSUtils.isViewFS(source, CachedConfiguration.getInstance())) { return ViewFSUtils.matchingFileSystem(source, options, CachedConfiguration.getInstance()); } } catch (IOException e) { throw new RuntimeException(e); } URI uri1 = source.toUri(); for (String option : options) { URI uri3 = URI.create(option); if (uri1.getScheme().equals(uri3.getScheme())) { String a1 = uri1.getAuthority(); String a2 = uri3.getAuthority(); if ((a1 == null && a2 == null) || (a1 != null && a1.equals(a2))) return new Path(option); } } return null; }
From source file:io.selendroid.server.model.SelendroidNativeDriver.java
public void get(String url) { URI dest; try {// w w w .ja v a 2s .co m dest = new URI(url); } catch (URISyntaxException exception) { throw new IllegalArgumentException(exception); } if (!"and-activity".equals(dest.getScheme())) { throw new SelendroidException("Unrecognized scheme in URI: " + dest.toString()); } else if (dest.getPath() != null && !dest.getPath().equals("")) { throw new SelendroidException("Unrecognized path in URI: " + dest.toString()); } URI currentUri = getCurrentURI(); if (currentUri != null && dest.getAuthority().endsWith(currentUri.getAuthority())) { // ignore request, activity is already open return; } serverInstrumentation.startActivity(dest.getAuthority()); DefaultSelendroidDriver.sleepQuietly(500); }
From source file:org.apache.hadoop.fs.swift.snative.SwiftNativeFileSystem.java
/** * Return an array containing hostnames, offset and size of * portions of the given file. For a nonexistent * file or regions, null will be returned. * <p/>/*from w w w. j av a2s . co m*/ * This call is most helpful with DFS, where it returns * hostnames of machines that contain the given file. * <p/> * The FileSystem will simply return an elt containing 'localhost'. */ @Override public BlockLocation[] getFileBlockLocations(FileStatus status, long start, long len) throws IOException { //argument checks if (status == null) { return null; } if (start < 0 || len < 0) { throw new IllegalArgumentException("Negative start or len parameter" + " to getFileBlockLocations"); } if (status.getLen() <= start) { return new BlockLocation[0]; } // Check if requested file in Swift is more than 5Gb. In this case // each block has its own location -which may be determinable // from the Swift client API, depending on the remote server final FileStatus[] listOfFileBlocks = store.listSubPaths(status.getPath(), false, true); List<URI> locations = new ArrayList<URI>(); if (listOfFileBlocks.length > 1) { for (FileStatus fileStatus : listOfFileBlocks) { if (SwiftObjectPath.fromPath(uri, fileStatus.getPath()) .equals(SwiftObjectPath.fromPath(uri, status.getPath()))) { continue; } locations.addAll(store.getObjectLocation(fileStatus.getPath())); } } else { locations = store.getObjectLocation(status.getPath()); } if (locations.isEmpty()) { LOG.info("No locations returned for " + status.getPath()); //no locations were returned for the object //fall back to the superclass return super.getFileBlockLocations(status, start, len); } final String[] names = new String[locations.size()]; final String[] hosts = new String[locations.size()]; int i = 0; for (URI location : locations) { hosts[i] = location.getHost(); names[i] = location.getAuthority(); i++; } return new BlockLocation[] { new BlockLocation(names, hosts, 0, status.getLen()) }; }
From source file:org.apache.camel.component.routebox.RouteboxConfiguration.java
public void parseURI(URI uri, Map<String, Object> parameters, RouteboxComponent component) throws Exception { String protocol = uri.getScheme(); if (!protocol.equalsIgnoreCase("routebox")) { throw new IllegalArgumentException("Unrecognized protocol: " + protocol + " for uri: " + uri); }// w w w . j a v a2 s . c o m setUri(uri); setAuthority(uri.getAuthority()); if (LOG.isTraceEnabled()) { LOG.trace("Authority: " + uri.getAuthority()); } setEndpointName(getAuthority()); if (parameters.containsKey("threads")) { setThreads(Integer.valueOf((String) parameters.get("threads"))); } if (parameters.containsKey("forkContext")) { if (!(Boolean.valueOf((String) parameters.get("forkContext")))) { setForkContext(false); } } if (parameters.containsKey("innerProtocol")) { setInnerProtocol((String) parameters.get("innerProtocol")); if ((!innerProtocol.equalsIgnoreCase("seda")) && (!innerProtocol.equalsIgnoreCase("direct"))) { throw new IllegalArgumentException( "Unrecognized inner protocol: " + innerProtocol + " for uri: " + uri); } } else { setInnerProtocol("direct"); } if (parameters.containsKey("sendToConsumer")) { if (!Boolean.valueOf((String) parameters.get("sendToConsumer"))) { setSendToConsumer(false); } } if (parameters.containsKey("connectionTimeout")) { setConnectionTimeout(Long.parseLong((String) parameters.get("connectionTimeout"))); } if (parameters.containsKey("pollInterval")) { setConnectionTimeout(Long.parseLong((String) parameters.get("pollInterval"))); } if (parameters.containsKey("routeBuilders")) { routeBuilders = (List<RouteBuilder>) component.resolveAndRemoveReferenceParameter(parameters, "routeBuilders", List.class); } if (parameters.containsKey("innerRegistry")) { innerRegistry = component.resolveAndRemoveReferenceParameter(parameters, "innerRegistry", Registry.class); } if (isForkContext()) { if (innerRegistry != null) { innerContext = component.resolveAndRemoveReferenceParameter(parameters, "innerContext", CamelContext.class, new DefaultCamelContext(innerRegistry)); } else { innerContext = component.resolveAndRemoveReferenceParameter(parameters, "innerContext", CamelContext.class, new DefaultCamelContext()); } } else { innerContext = component.getCamelContext(); } innerProducerTemplate = innerContext.createProducerTemplate(); setQueueSize(component.getAndRemoveParameter(parameters, "size", Integer.class, 0)); consumerUri = component.resolveAndRemoveReferenceParameter(parameters, "consumerUri", URI.class, new URI("routebox:" + getEndpointName())); producerUri = component.resolveAndRemoveReferenceParameter(parameters, "producerUri", URI.class, new URI("routebox:" + getEndpointName())); dispatchStrategy = component.resolveAndRemoveReferenceParameter(parameters, "dispatchStrategy", RouteboxDispatchStrategy.class, null); dispatchMap = (HashMap<String, String>) component.resolveAndRemoveReferenceParameter(parameters, "dispatchMap", HashMap.class, new HashMap<String, String>()); if (dispatchStrategy == null && dispatchMap == null) { LOG.warn( "No Routebox Dispatch Map or Strategy has been set. Routebox may not have more than one inner route."); } }
From source file:tachyon.TachyonURI.java
/** * Resolve a child TachyonURI against a parent TachyonURI. * * @param parent the parent/* w w w. jav a 2s.co m*/ * @param child the child */ public TachyonURI(TachyonURI parent, TachyonURI child) { // Add a slash to parent's path so resolution is compatible with URI's URI parentUri = parent.mUri; String parentPath = parentUri.getPath(); if (!parentPath.endsWith(SEPARATOR) && parentPath.length() > 0) { parentPath += SEPARATOR; } try { parentUri = new URI(parentUri.getScheme(), parentUri.getAuthority(), parentPath, null, null); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } URI resolved = parentUri.resolve(child.mUri); mUri = createURI(resolved.getScheme(), resolved.getAuthority(), resolved.getPath()); }
From source file:org.openqa.selendroid.server.model.SelendroidNativeDriver.java
public void get(String url) { URI dest; try {/*from w ww .j a v a 2 s . c o m*/ dest = new URI(url); } catch (URISyntaxException exception) { throw new IllegalArgumentException(exception); } if (!"and-activity".equals(dest.getScheme())) { throw new SelendroidException("Unrecognized scheme in URI: " + dest.toString()); } else if (dest.getPath() != null && !dest.getPath().equals("")) { throw new SelendroidException("Unrecognized path in URI: " + dest.toString()); } URI currentUri = getCurrentURI(); if (currentUri != null && dest.getAuthority().endsWith(currentUri.getAuthority())) { // ignore request, activity is already open return; } Class<?> clazz; try { clazz = Class.forName(dest.getAuthority()); } catch (ClassNotFoundException exception) { exception.printStackTrace(); throw new SelendroidException("The specified Activity class does not exist: " + dest.getAuthority(), exception); } serverInstrumentation.startActivity(clazz); DefaultSelendroidDriver.sleepQuietly(500); }