List of usage examples for java.net URI getScheme
public String getScheme()
From source file:com.aliyun.oss.integrationtests.TestUtils.java
public static String composeLocation(OSSClient client, String endpoint, String bucketName, String key) { try {/*from www . j av a2s . co m*/ URI baseUri = URI.create(endpoint); URI resultUri = null; if (client.getClientConfiguration().isSLDEnabled()) { resultUri = new URI(baseUri.getScheme(), null, baseUri.getHost(), baseUri.getPort(), String.format("/%s/%s", bucketName, HttpUtil.urlEncode(key, DEFAULT_CHARSET_NAME)), null, null); } else { resultUri = new URI(baseUri.getScheme(), null, bucketName + "." + baseUri.getHost(), baseUri.getPort(), String.format("/%s", HttpUtil.urlEncode(key, DEFAULT_CHARSET_NAME)), null, null); } return URLDecoder.decode(resultUri.toString(), DEFAULT_CHARSET_NAME); } catch (Exception e) { throw new IllegalArgumentException(e.getMessage(), e); } }
From source file:com.microsoft.alm.common.utils.UrlHelper.java
public static String getHttpsUrlFromHttpUrl(final String httpUrl) { final URI uri = createUri(httpUrl); String httpsUrl = httpUrl;/*from w w w.j av a 2s . c om*/ if (uri != null && StringUtils.equalsIgnoreCase(uri.getScheme(), "http")) { final URI httpsUri = createUri("https://" + uri.getAuthority() + uri.getPath()); httpsUrl = httpsUri.toString(); } if (StringUtils.startsWithIgnoreCase(httpsUrl, "https://")) { return httpsUrl; } else { return null; } }
From source file:com.ibm.jaggr.service.impl.deps.DepUtils.java
/** * Maps a resource URI to a {@link DepTreeNode}. This routine finds the key * in <code>dependencies</code> that is an ancestor of * <code>requiestURI</code> and then looks for the {@link DepTreeNode} who's * name corresponds to descendant part of the URI path. * /*from w w w . j a va 2 s . c om*/ * @param requestUri * The URI for the resource location being sought * @param dependencies * Map of file path names to root {@link DepTreeNode}s * @return The node corresponding to <code>requestURI</code> */ static public DepTreeNode getNodeForResource(URI requestUri, Map<URI, DepTreeNode> dependencies) { DepTreeNode result = null; /* * Iterate through the map entries and find the entry who's key is the same, * or an ancestor of, the specified path */ for (Entry<URI, DepTreeNode> dependency : dependencies.entrySet()) { URI uri = dependency.getKey(); if (requestUri.getScheme() == null && uri.getScheme() != null || requestUri.getScheme() != null && !requestUri.getScheme().equals(uri.getScheme())) continue; if (requestUri.getHost() == null && uri.getHost() != null || requestUri.getHost() != null && !requestUri.getHost().equals(uri.getHost())) continue; if (requestUri.getPath().equals(uri.getPath()) || requestUri.getPath().startsWith(uri.getPath()) && (uri.getPath().endsWith("/") || requestUri.getPath().charAt(uri.getPath().length()) == '/')) //$NON-NLS-1$ { /* * Found the entry. Now find the node corresponding to the * remainder of the path. */ if (requestUri.getPath().equals(uri.getPath())) { return dependency.getValue(); } else { String modulePath = requestUri.getPath().substring(uri.getPath().length()); if (modulePath.startsWith("/")) { //$NON-NLS-1$ modulePath = modulePath.substring(1); } result = dependency.getValue().getDescendent(modulePath); } break; } } return result; }
From source file:com.ibm.jaggr.core.impl.deps.DepUtils.java
/** * Maps a resource URI to a {@link DepTreeNode}. This routine finds the key * in <code>dependencies</code> that is an ancestor of * <code>requiestURI</code> and then looks for the {@link DepTreeNode} who's * name corresponds to descendant part of the URI path. * * @param requestUri//w w w .j a va2 s . co m * The URI for the resource location being sought * @param dependencies * Map of file path names to root {@link DepTreeNode}s * @return The node corresponding to <code>requestURI</code> */ static public DepTreeNode getNodeForResource(URI requestUri, Map<URI, DepTreeNode> dependencies) { DepTreeNode result = null; /* * Iterate through the map entries and find the entry who's key is the same, * or an ancestor of, the specified path */ for (Entry<URI, DepTreeNode> dependency : dependencies.entrySet()) { URI uri = dependency.getKey(); if (requestUri.getScheme() == null && uri.getScheme() != null || requestUri.getScheme() != null && !requestUri.getScheme().equals(uri.getScheme())) continue; if (requestUri.getHost() == null && uri.getHost() != null || requestUri.getHost() != null && !requestUri.getHost().equals(uri.getHost())) continue; if (requestUri.getPath().equals(uri.getPath()) || requestUri.getPath().startsWith(uri.getPath()) && (uri.getPath().endsWith("/") || requestUri.getPath().charAt(uri.getPath().length()) == '/')) //$NON-NLS-1$ { /* * Found the entry. Now find the node corresponding to the * remainder of the path. */ if (requestUri.getPath().equals(uri.getPath())) { return dependency.getValue(); } else { String modulePath = requestUri.getPath().substring(uri.getPath().length()); if (modulePath.startsWith("/")) { //$NON-NLS-1$ modulePath = modulePath.substring(1); } result = dependency.getValue().getDescendent(modulePath); } break; } } return result; }
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 . co m*/ 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:com.taobao.datax.plugins.common.DFSUtils.java
/** * Get {@link Configuration}.// w w w .java 2 s . co m * * @param dir * directory path in hdfs * * @param ugi * hadoop ugi * * @param conf * hadoop-site.xml path * * @return {@link Configuration} * * @throws java.io.IOException*/ public static Configuration getConf(String dir, String ugi, String conf) throws IOException { URI uri = null; Configuration cfg = null; String scheme = null; try { uri = new URI(dir); scheme = uri.getScheme(); if (null == scheme) { throw new IOException("HDFS Path missing scheme, check path begin with hdfs://ip:port/ ."); } cfg = confs.get(scheme); } catch (URISyntaxException e) { throw new IOException(e.getMessage(), e.getCause()); } if (cfg == null) { cfg = new Configuration(); cfg.setClassLoader(DFSUtils.class.getClassLoader()); List<String> configs = new ArrayList<String>(); if (!StringUtils.isBlank(conf) && new File(conf).exists()) { configs.add(conf); } else { /* * For taobao internal use e.g. if bazhen.csy start a new datax * job, datax will use /home/bazhen.csy/config/hadoop-site.xml * as configuration xml */ String confDir = System.getenv("HADOOP_CONF_DIR"); if (null == confDir) { //for taobao internal use, it is ugly configs.add(System.getProperty("user.home") + "/config/hadoop-site.xml"); } else { //run in hadoop-0.19 if (new File(confDir + "/hadoop-site.xml").exists()) { configs.add(confDir + "/hadoop-site.xml"); } else { configs.add(confDir + "/core-default.xml"); configs.add(confDir + "/core-site.xml"); } } } for (String config : configs) { log.info(String.format("HdfsReader use %s for hadoop configuration .", config)); cfg.addResource(new Path(config)); } /* commented by bazhen.csy */ // log.info("HdfsReader use default ugi " + // cfg.get(ParamsKey.HdfsReader.ugi)); if (uri.getScheme() != null) { String fsname = String.format("%s://%s:%s", uri.getScheme(), uri.getHost(), uri.getPort()); log.info("fs.default.name=" + fsname); cfg.set("fs.default.name", fsname); } if (ugi != null) { cfg.set("hadoop.job.ugi", ugi); /* * commented by bazhen.csy log.info("use specification ugi:" + * cfg.get(ParamsKey.HdfsReader.ugi)); */ } confs.put(scheme, cfg); } return cfg; }
From source file:com.ibm.amc.FileManager.java
/** * Engage the reference-counting function for a temporary upload file. This * is for use when a series of actions is to take place in quick succession * using the same temporary file. By "quick succession", we mean as part of * the same ReST call. This is not intended for use between calls from the * client./*from w ww .j a v a 2 s .c o m*/ * <br><br> * Each action calls this method as early as possible in its execution, to * register its interest in the file. When the action has finished with the * file, it calls the corresponding decrement method. Once the number of * decrements matches the number of increments, everybody has finished with * the file and it will be immediately deleted (before the last decrement * call returns). * <br><br> * Files using this mechanism are not immune from deletion by the * housekeeper even while they still have references, but this should not * cause a problem unless your actions are taking a significant portion of * a day to complete. * @param file The file to count references for. Non-FileManager URIs can * be passed, but they will be silently ignored and no references maintained * for them; we wouldn't be able to delete them anyway. */ // This is all lost if we get restarted. That's fine, the actions will be // lost too, and the housekeeper will tidy it all up eventually. public static synchronized void incrementReferenceCount(URI file) { if (logger.isEntryEnabled()) logger.entry("incrementReferenceCount", file); if (file == null) return; if (!file.getScheme().equalsIgnoreCase(SCHEME)) return; // Only manage our own files. Integer count = references.get(file); if (count == null) count = 0; references.put(file, ++count); if (logger.isDebugEnabled()) logger.debug("incrementReferenceCount()", "Reference count increased to " + count + " for " + file); if (logger.isEntryEnabled()) logger.exit("incrementReferenceCount"); }
From source file:org.apache.jena.jdbc.remote.RemoteEndpointDriver.java
/** * Strips the last component of the given URI if possible * /* w ww . j a va2s .com*/ * @param input * URI * @return Reduced URI or null if no further reduction is possible */ private static String stripLastComponent(String input) { try { URI uri = new URI(input); if (uri.getFragment() != null) { return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), null).toString(); } else if (uri.getQuery() != null) { return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), null, null).toString(); } else if (uri.getPath() != null) { // Try and strip off last segment of the path String currPath = uri.getPath(); if (currPath.endsWith("/")) { currPath = currPath.substring(0, currPath.length() - 1); if (currPath.length() == 0) currPath = null; return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), currPath, null, null).toString(); } else if (currPath.contains("/")) { currPath = currPath.substring(0, currPath.lastIndexOf('/') + 1); if (currPath.length() == 0) currPath = null; return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), currPath, null, null).toString(); } else { // If path is non-null it must always contain a / // otherwise it would be an invalid path // In this case there are no further components to strip return null; } } else { // No further components to strip return null; } } catch (URISyntaxException e) { // Error stripping component return null; } }
From source file:com.adaptris.core.management.jetty.FromXmlConfig.java
private static URL createUrlFromString(String s) throws Exception { String destToConvert = backslashToSlash(s); URI configuredUri = null; try {/*from www .ja v a 2 s.c o m*/ configuredUri = new URI(destToConvert); } catch (URISyntaxException e) { // Specifically here to cope with file:///c:/ (which is // technically illegal according to RFC2396 but we need // to support it if (destToConvert.split(":").length >= 3) { configuredUri = new URI(URLEncoder.encode(destToConvert, "UTF-8")); } else { throw e; } } return configuredUri.getScheme() == null ? relativeConfig(configuredUri) : new URL(configuredUri.toString()); }
From source file:com.ibm.amc.FileManager.java
/** * Indicate that the caller no longer needs the file. If nobody else needs * it either, it will be deleted. See the incrementReferenceCount method for * details./* w ww.j a va2 s. c o m*/ * @param file The file to count references for. Non-FileManager URIs can * be passed, but they will be silently ignored and no references maintained * for them; we wouldn't be able to delete them anyway. */ public static synchronized void decrementReferenceCount(URI file) { if (logger.isEntryEnabled()) logger.entry("decrementReferenceCount", file); if (file == null) return; if (!file.getScheme().equalsIgnoreCase(SCHEME)) return; // Only manage our own files. Integer count = references.get(file); if (count != null) { count--; references.put(file, count); if (logger.isDebugEnabled()) logger.debug("decrementReferenceCount()", "Reference count decreased to " + count + " for " + file); if (count < 1) { if (logger.isDebugEnabled()) logger.debug("decrementReferenceCount()", "No more references to " + file + "; deleting."); deleteIfTemporaryFile(file); } } if (logger.isEntryEnabled()) logger.exit("decrementReferenceCount"); }