List of usage examples for java.net URI toString
public String toString()
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 {// www . j a v a 2 s .c o 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.microsoft.alm.common.utils.UrlHelper.java
public static String asString(final URI uri) { if (uri != null) { return uri.toString(); }// ww w. ja va2s .c o m return null; }
From source file:info.rmapproject.webapp.utils.WebappUtils.java
/** * HTTP encode a URI//from w w w . j a va2 s . c o m * * @param value the URI to encode * @return the encoded HTTP string * @throws UnsupportedEncodingException the unsupported encoding exception */ public static String httpEncode(URI value) throws UnsupportedEncodingException { if (value == null) { return ""; } return URLEncoder.encode(value.toString(), "UTF-8"); }
From source file:ratpack.spring.config.RatpackProperties.java
static Path resourceToPath(URL resource) { Objects.requireNonNull(resource, "Resource URL cannot be null"); URI uri; try {/*from w w w . ja v a 2s.co m*/ uri = resource.toURI(); } catch (URISyntaxException e) { throw new IllegalArgumentException("Could not extract URI", e); } String scheme = uri.getScheme(); if (scheme.equals("file")) { String path = uri.toString().substring("file:".length()); if (path.contains("//")) { path = StringUtils.cleanPath(path.replace("//", "")); } return Paths.get(new FileSystemResource(path).getFile().toURI()); } if (!scheme.equals("jar")) { throw new IllegalArgumentException("Cannot convert to Path: " + uri); } String s = uri.toString(); int separator = s.indexOf("!/"); String entryName = s.substring(separator + 2); URI fileURI = URI.create(s.substring(0, separator)); FileSystem fs; try { fs = FileSystems.newFileSystem(fileURI, Collections.<String, Object>emptyMap()); return fs.getPath(entryName); } catch (IOException e) { throw new IllegalArgumentException("Could not create file system for resource: " + resource, e); } }
From source file:org.wrml.runtime.rest.RestUtils.java
public static final Set<Header> extractRequestHeaders(final Context context, final Dimensions requestedDimensions) { final Set<Header> headers = new LinkedHashSet<>(); final String acceptHeaderValue = RestUtils.extractMediaTypeFromDimensions(context, requestedDimensions) .toString();//w ww .j a va 2s . c o m final Header acceptHeader = new BasicHeader(CommonHeader.ACCEPT.getName(), acceptHeaderValue); headers.add(acceptHeader); final URI referrerUri = requestedDimensions.getReferrerUri(); if (referrerUri != null) { headers.add(new BasicHeader(CommonHeader.REFERER.getName(), referrerUri.toString())); } final Locale locale = requestedDimensions.getLocale(); if (locale != null) { final SyntaxLoader syntaxLoader = context.getSyntaxLoader(); final String languageHeaderValue = syntaxLoader.formatSyntaxValue(locale); headers.add(new BasicHeader(CommonHeader.ACCEPT_LANGUAGE.getName(), languageHeaderValue)); } final Map<String, String> metadataMap = requestedDimensions.getMetadata(); if (metadataMap != null && !metadataMap.isEmpty()) { for (final String metadataName : metadataMap.keySet()) { final String metadataValue = metadataMap.get(metadataName); final Header additionalHeader = new BasicHeader(metadataName, metadataValue); headers.add(additionalHeader); } } return headers; }
From source file:com.feilong.core.net.ParamExtensionUtil.java
/** * ?.//from w w w . jav a 2 s. co m * * <p> * uri????,?,?{@code a=1&a=2},a,[3,4],{@code a=3&a=4}. * </p> * * @param uri * ? ?,?,??,<br> * ??, ? * @param arrayValueMap * singleValueMap request.getParameterMap * @param charsetType * ??, {@link CharsetType}<br> * <span style="color:green">null empty,?,?</span><br> * ??,??,ie?chrome? url ,? * @return <code>uri</code> null, {@link StringUtils#EMPTY}<br> */ public static String addParameterArrayValueMap(URI uri, Map<String, String[]> arrayValueMap, String charsetType) { return null == uri ? EMPTY : ParamUtil.addParameterArrayValueMap(uri.toString(), uri.getRawQuery(), arrayValueMap, charsetType); }
From source file:com.microsoft.alm.common.utils.UrlHelper.java
public static URI getBuildURI(final URI projectUri, final int buildId) { return UrlHelper.createUri(projectUri.toString().concat(URL_SEPARATOR).concat(URL_BUILD_PATH_SEGMENT) .concat(String.format(URL_BUILD_SPECIFIC_ITEM_PATH_SEGMENT, buildId))); }
From source file:it.infn.ct.InstantiateVM.java
public static String doCreate(Properties properties, EntityBuilder eb, Model model, Client client, JSONObject egiInput) {//from w ww. ja v a2 s. c o m URI uri_location = null; String networkInterfaceLocation = ""; String networkInterfaceLocation_stripped = ""; Resource vm_resource = null; try { if (properties.getProperty("RESOURCE").equals("compute")) { String segments[] = properties.getProperty("OCCI_OS_TPL").split("#"); String OCCI_OS_TPL = segments[segments.length - 1]; String segments2[] = properties.getProperty("OCCI_RESOURCE_TPL").split("#"); String OCCI_RESOURCE_TPL = segments2[segments2.length - 1]; System.out.println("[+] Creating a new compute Virtual Machine (VM)"); // Creating a compute instance Resource compute = eb.getResource("compute"); Mixin mixin = model.findMixin(OCCI_OS_TPL); compute.addMixin(mixin); compute.addMixin(model.findMixin(OCCI_OS_TPL, "os_tpl")); compute.addMixin(model.findMixin(OCCI_RESOURCE_TPL, "resource_tpl")); // Checking the context if (properties.getProperty("PUBLIC_KEY_FILE") != null && !properties.getProperty("PUBLIC_KEY_FILE").isEmpty()) { String _public_key_file = properties.getProperty("PUBLIC_KEY_FILE") .substring(properties.getProperty("PUBLIC_KEY_FILE").lastIndexOf(":") + 1); File f = new File(_public_key_file); FileInputStream fis = new FileInputStream(f); DataInputStream dis = new DataInputStream(fis); byte[] keyBytes = new byte[(int) f.length()]; dis.readFully(keyBytes); dis.close(); String _publicKey = new String(keyBytes).trim(); // Add SSH public key compute.addMixin(model .findMixin(URI.create("http://schemas.openstack.org/instance/credentials#public_key"))); compute.addAttribute("org.openstack.credentials.publickey.data", _publicKey); // Add the name for the public key if (OCCI_PUBLICKEY_NAME != null && !OCCI_PUBLICKEY_NAME.isEmpty()) compute.addAttribute("org.openstack.credentials.publickey.name", properties.getProperty("OCCI_PUBLICKEY_NAME")); } if (properties.getProperty("USER_DATA") != null && !properties.getProperty("USER_DATA").isEmpty()) { String _user_data = properties.getProperty("USER_DATA") .substring(properties.getProperty("USER_DATA").lastIndexOf(":") + 1); File f = new File(_user_data); FileInputStream fis = new FileInputStream(f); DataInputStream dis = new DataInputStream(fis); byte[] keyBytes = new byte[(int) f.length()]; dis.readFully(keyBytes); dis.close(); byte[] data = Base64.encodeBase64(keyBytes); String user_data = new String(data); compute.addMixin( model.findMixin(URI.create("http://schemas.openstack.org/compute/instance#user_data"))); compute.addAttribute("org.openstack.compute.user_data", user_data); } // Set VM title compute.setTitle(properties.getProperty("OCCI_CORE_TITLE")); URI location = client.create(compute); return location.toString(); } if (properties.getProperty("RESOURCE").equals("storage")) { System.out.println("[+] Creating a volume storage"); // Creating a storage instance Storage storage = eb.getStorage(); storage.setTitle(properties.getProperty("OCCI_CORE_TITLE")); storage.setSize(properties.getProperty("OCCI_STORAGE_SIZE")); URI storageLocation = client.create(storage); List<URI> list = client.list("storage"); List<URI> storageURIs = new ArrayList<URI>(); for (URI uri : list) { if (uri.toString().contains("storage")) storageURIs.add(uri); } System.out.println("URI = " + storageLocation); } } catch (FileNotFoundException ex) { throw new RuntimeException(ex); } catch (IOException ex) { throw new RuntimeException(ex); } catch (EntityBuildingException | AmbiguousIdentifierException | InvalidAttributeValueException | CommunicationException ex) { throw new RuntimeException(ex); } return ""; }
From source file:com.eucalyptus.blockstorage.entities.SnapshotInfo.java
/** * Generate snapshot location uri in the format: snapshots://server/bucket/key * //from ww w . j ava 2 s. c o m * @param server * @param bucket * @param key * @return * @throws URISyntaxException * @throws EucalyptusCloudException */ public static String generateSnapshotLocationURI(String server, String bucket, String key) throws URISyntaxException, EucalyptusCloudException { if (StringUtils.isNotBlank(bucket) && StringUtils.isNotBlank(key)) { URI snapshotUri = new URI(AUTHORITY, server, ('/' + bucket + '/' + key), null, null); return snapshotUri.toString(); } else { throw new EucalyptusCloudException( "Invalid bucket and or key names. Bucket: " + bucket + ", Key: " + key); } }
From source file:com.microsoft.alm.common.utils.UrlHelper.java
public static URI getSpecificWorkItemURI(final URI projectUri, final int workItemId) { return UrlHelper.createUri(projectUri.toString().concat(URL_SEPARATOR).concat(URL_WIT_PATH_SEGMENT) .concat(String.format(URL_WIT_SPECIFIC_ITEM_PATH_SEGMENT, workItemId))); }