List of usage examples for java.net URI isOpaque
public boolean isOpaque()
From source file:Main.java
public static void main(String[] args) throws NullPointerException, URISyntaxException { URI uri = new URI("http://www.java2s.com"); System.out.println("URI : " + uri); System.out.println(uri.isOpaque()); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { URI u = new URI("http://www.java2s.com"); System.out.println("The URI is " + u); if (u.isOpaque()) { System.out.println("This is an opaque URI."); System.out.println("The scheme is " + u.getScheme()); System.out.println("The scheme specific part is " + u.getSchemeSpecificPart()); System.out.println("The fragment ID is " + u.getFragment()); } else {// ww w . ja va 2 s. c om System.out.println("This is a hierarchical URI."); System.out.println("The scheme is " + u.getScheme()); u = u.parseServerAuthority(); System.out.println("The host is " + u.getUserInfo()); System.out.println("The user info is " + u.getUserInfo()); System.out.println("The port is " + u.getPort()); System.out.println("The path is " + u.getPath()); System.out.println("The query string is " + u.getQuery()); System.out.println("The fragment ID is " + u.getFragment()); } }
From source file:com.textocat.textokit.commons.io.IoUtils.java
/** * @param uri a source URI/*from ww w . j a va 2 s. c o m*/ * @return a Path part from the given URI, never null */ public static Path extractPath(URI uri) { if (uri.isOpaque()) { throw new IllegalArgumentException(format("Opaque URIs are not supported: %s", uri)); } String path = uri.getPath(); Preconditions.checkState(path != null, "URI path is null: " + uri); return Paths.get(path); }
From source file:com.marklogic.mapreduce.utilities.URIUtil.java
public static String getPathFromURI(DocumentURI uri) { String uriStr = uri.getUri(); try {//from ww w . java2 s .com URI child = new URI(uriStr); String childPath; if (child.isOpaque()) { childPath = child.getSchemeSpecificPart(); } else { childPath = child.getPath(); } return childPath; } catch (Exception ex) { LOG.warn("Error parsing URI " + uriStr + "."); return uriStr; } }
From source file:com.microsoft.gittf.core.util.URIUtil.java
/** * Converts the specified string into a valid server URI. The method will * update the URI if needed when connecting to the hosted service, to make * sure that the connection is HTTPS and is to the default collection * /*from w w w . ja va 2s . c om*/ * @param serverURIString * the uri string to convert * @return * @throws Exception */ public static URI getServerURI(final String serverURIString) throws Exception { try { URI uri = new URI(serverURIString); if (!uri.isAbsolute() || uri.isOpaque()) { uri = null; } if (uri != null) { uri = updateIfNeededForHostedService(uri); } if (uri == null) { throw new Exception(Messages.formatString("URIUtil.InvalidURIFormat", serverURIString)); //$NON-NLS-1$ } return uri; } catch (Exception e) { log.warn("Could not parse URI", e); //$NON-NLS-1$ } throw new Exception(Messages.formatString("URIUtil.InvalidURIFormat", serverURIString)); //$NON-NLS-1$ }
From source file:com.textocat.textokit.commons.util.DocumentUtils.java
public static String getFilename(String uriStr) throws URISyntaxException { URI uri = new URI(uriStr); String path;/*from ww w .j a va 2s. c o m*/ if (uri.isOpaque()) { // TODO this is a hotfix. In future we should avoid setting opaque source URIs in DocumentMetadata path = uri.getSchemeSpecificPart(); } else { path = uri.getPath(); } return FilenameUtils.getName(path); }
From source file:edu.usc.goffish.gofs.namenode.DataNode.java
private static Path convertLocalURIToPath(URI localURI) throws IOException { if (localURI == null || localURI.isOpaque() || !localURI.isAbsolute() || !"file".equalsIgnoreCase(localURI.getScheme())) { throw new IllegalArgumentException(); }//from ww w . j av a 2 s . co m if (!URIHelper.isLocalURI(localURI)) { throw new IOException("uri host " + localURI.getHost() + " is not local"); } String path = localURI.getPath(); if (path == null) { path = "/"; } return Paths.get(URI.create("file://" + path)); }
From source file:com.marklogic.contentpump.SingleDocumentWriter.java
protected static String getPathFromURI(DocumentURI uri) { String uriStr = uri.getUri(); try {// ww w . j a v a2 s .c om URI child = new URI(uriStr); String childPath; if (child.isOpaque()) { childPath = child.getSchemeSpecificPart(); } else { childPath = child.getPath(); } return childPath; } catch (Exception ex) { LOG.error("Error parsing URI " + uriStr + "."); return uriStr; } }
From source file:gobblin.util.ClustersNames.java
private static String normalizeClusterUrl(String clusterIdentifier) { try {/*from w w w . j a v a 2 s . c om*/ URI uri = new URI(clusterIdentifier.trim()); // URIs without protocol prefix if (!uri.isOpaque() && null != uri.getHost()) { clusterIdentifier = uri.getHost(); } else { clusterIdentifier = uri.toString().replaceAll("[/:]", " ").trim().replaceAll(" ", "_"); } } catch (URISyntaxException e) { //leave ID as is } return clusterIdentifier; }
From source file:com.microsoft.tfs.core.util.URIUtils.java
/** * <p>/* w w w . j ava 2 s . c o m*/ * Ensures that all the components of the {@link URI} are in lower-case. * </p> * * <p> * If the specified {@link URI} is opaque, it is returned. Otherwise, a new * {@link URI} is returned that is identical to the specified {@link URI} * except that the components (scheme, hostname, path) are converted to * their lower case equivalents (in a generic locale.) * </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 toLowerCase(final URI uri) { Check.notNull(uri, "uri"); //$NON-NLS-1$ if (uri.isOpaque()) { return uri; } final String scheme = uri.getScheme() != null ? uri.getScheme().toLowerCase(LocaleUtil.ROOT) : null; final String authority = uri.getAuthority() != null ? uri.getAuthority().toLowerCase(LocaleUtil.ROOT) : null; final String path = uri.getPath() != null ? uri.getPath().toLowerCase(LocaleUtil.ROOT) : null; final String query = uri.getQuery() != null ? uri.getQuery().toLowerCase(LocaleUtil.ROOT) : null; final String fragment = uri.getFragment() != null ? uri.getFragment().toLowerCase(LocaleUtil.ROOT) : null; return newURI(scheme, authority, path, query, fragment); }