Java Code Examples for java.net.URI#getRawSchemeSpecificPart()

The following examples show how to use java.net.URI#getRawSchemeSpecificPart() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: URIBuilder.java    From nano-framework with Apache License 2.0 6 votes vote down vote up
public URIBuilder digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery());
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
    return this;
}
 
Example 2
Source File: URISupport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a URI with the given query, removing an previous query value from the given URI.
 *
 * @param uri   The source URI whose existing query is replaced with the newly supplied one.
 * @param query The new URI query string that should be appended to the given URI.
 * @return a new URI that is a combination of the original URI and the given query string.
 * @throws java.net.URISyntaxException
 */
public static URI createURIWithQuery(URI uri, String query) throws URISyntaxException {
   String schemeSpecificPart = uri.getRawSchemeSpecificPart();
   // strip existing query if any
   int questionMark = schemeSpecificPart.lastIndexOf("?");
   // make sure question mark is not within parentheses
   if (questionMark < schemeSpecificPart.lastIndexOf(")")) {
      questionMark = -1;
   }
   if (questionMark > 0) {
      schemeSpecificPart = schemeSpecificPart.substring(0, questionMark);
   }
   if (query != null && query.length() > 0) {
      schemeSpecificPart += "?" + query;
   }
   return new URI(uri.getScheme(), schemeSpecificPart, uri.getFragment());
}
 
Example 3
Source File: ZipFileSystemProvider.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected Path uriToPath(URI uri) {
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) {
        throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'");
    }
    try {
        // only support legacy JAR URL syntax  jar:{uri}!/{entry} for now
        String spec = uri.getRawSchemeSpecificPart();
        int sep = spec.indexOf("!/");
        if (sep != -1)
            spec = spec.substring(0, sep);
        return Paths.get(new URI(spec)).toAbsolutePath();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
Example 4
Source File: ZipFileSystemProvider.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected Path uriToPath(URI uri) {
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) {
        throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'");
    }
    try {
        // only support legacy JAR URL syntax  jar:{uri}!/{entry} for now
        String spec = uri.getRawSchemeSpecificPart();
        int sep = spec.indexOf("!/");
        if (sep != -1)
            spec = spec.substring(0, sep);
        return Paths.get(new URI(spec)).toAbsolutePath();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
Example 5
Source File: BundleFileSystem.java    From incubator-taverna-language with Apache License 2.0 6 votes vote down vote up
protected Path findSource() {
	Path zipRoot = getRootDirectory().getZipPath();
	URI uri = zipRoot.toUri();
	String schemeSpecific;
	if (provider().getJarDoubleEscaping()) {
		schemeSpecific = uri.getSchemeSpecificPart();
	} else {
		// http://dev.mygrid.org.uk/issues/browse/T3-954
		schemeSpecific = uri.getRawSchemeSpecificPart();
	}
	if (!schemeSpecific.endsWith("!/")) { // sanity check
		throw new IllegalStateException("Can't parse JAR URI: " + uri);
	}
	URI zip = URI.create(schemeSpecific.substring(0,
			schemeSpecific.length() - 2));
	return Paths.get(zip); // Look up our path
}
 
Example 6
Source File: PropertyUtil.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a URI with the given query, removing an previous query value from the given URI.
 *
 * @param uri   The source URI whose existing query is replaced with the newly supplied one.
 * @param query The new URI query string that should be appended to the given URI.
 * @return a new URI that is a combination of the original URI and the given query string.
 * @throws URISyntaxException if the given URI is invalid.
 */
public static URI replaceQuery(URI uri, String query) throws URISyntaxException {
   String schemeSpecificPart = uri.getRawSchemeSpecificPart();
   // strip existing query if any
   int questionMark = schemeSpecificPart.lastIndexOf("?");
   // make sure question mark is not within parentheses
   if (questionMark < schemeSpecificPart.lastIndexOf(")")) {
      questionMark = -1;
   }
   if (questionMark > 0) {
      schemeSpecificPart = schemeSpecificPart.substring(0, questionMark);
   }
   if (query != null && query.length() > 0) {
      schemeSpecificPart += "?" + query;
   }
   return new URI(uri.getScheme(), schemeSpecificPart, uri.getFragment());
}
 
Example 7
Source File: ZipFileSystemProvider.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
protected Path uriToPath(URI uri) {
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) {
        throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'");
    }
    try {
        // only support legacy JAR URL syntax  jar:{uri}!/{entry} for now
        String spec = uri.getRawSchemeSpecificPart();
        int sep = spec.indexOf("!/");
        if (sep != -1)
            spec = spec.substring(0, sep);
        return Paths.get(new URI(spec)).toAbsolutePath();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
Example 8
Source File: ZipFileSystemProvider.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected Path uriToPath(URI uri) {
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) {
        throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'");
    }
    try {
        // only support legacy JAR URL syntax  jar:{uri}!/{entry} for now
        String spec = uri.getRawSchemeSpecificPart();
        int sep = spec.indexOf("!/");
        if (sep != -1)
            spec = spec.substring(0, sep);
        return Paths.get(new URI(spec)).toAbsolutePath();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
Example 9
Source File: ZipFileSystemProvider.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected Path uriToPath(URI uri) {
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) {
        throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'");
    }
    try {
        // only support legacy JAR URL syntax  jar:{uri}!/{entry} for now
        String spec = uri.getRawSchemeSpecificPart();
        int sep = spec.indexOf("!/");
        if (sep != -1) {
            spec = spec.substring(0, sep);
        }
        return Paths.get(new URI(spec)).toAbsolutePath();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
Example 10
Source File: ZipFileSystemProvider.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
protected Path uriToPath(URI uri) {
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) {
        throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'");
    }
    try {
        // only support legacy JAR URL syntax  jar:{uri}!/{entry} for now
        String spec = uri.getRawSchemeSpecificPart();
        int sep = spec.indexOf("!/");
        if (sep != -1)
            spec = spec.substring(0, sep);
        return Paths.get(new URI(spec)).toAbsolutePath();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
Example 11
Source File: ZipFileSystemProvider.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected Path uriToPath(URI uri) {
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) {
        throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'");
    }
    try {
        // only support legacy JAR URL syntax  jar:{uri}!/{entry} for now
        String spec = uri.getRawSchemeSpecificPart();
        int sep = spec.indexOf("!/");
        if (sep != -1)
            spec = spec.substring(0, sep);
        return Paths.get(new URI(spec)).toAbsolutePath();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
Example 12
Source File: ZipFileSystemProvider.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected Path uriToPath(URI uri) {
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) {
        throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'");
    }
    try {
        // only support legacy JAR URL syntax  jar:{uri}!/{entry} for now
        String spec = uri.getRawSchemeSpecificPart();
        int sep = spec.indexOf("!/");
        if (sep != -1)
            spec = spec.substring(0, sep);
        return Paths.get(new URI(spec)).toAbsolutePath();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
Example 13
Source File: ZipFileSystemProvider.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected Path uriToPath(URI uri) {
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) {
        throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'");
    }
    try {
        // only support legacy JAR URL syntax  jar:{uri}!/{entry} for now
        String spec = uri.getRawSchemeSpecificPart();
        int sep = spec.indexOf("!/");
        if (sep != -1)
            spec = spec.substring(0, sep);
        return Paths.get(new URI(spec)).toAbsolutePath();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
Example 14
Source File: URIBuilder.java    From RoboZombie with Apache License 2.0 5 votes vote down vote up
private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8);
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}
 
Example 15
Source File: UriUtils.java    From vividus with Apache License 2.0 5 votes vote down vote up
public static URI createUri(String url)
{
    try
    {
        String decodedUrl = decode(url);

        int schemeSeparatorIndex = decodedUrl.indexOf(SCHEME_SEPARATOR);
        if (schemeSeparatorIndex < 0)
        {
            throw new IllegalArgumentException("Scheme is missing in URL: " + url);
        }
        String scheme = decodedUrl.substring(0, schemeSeparatorIndex);
        String decodedFragment = extractDecodedFragment(url);

        if (scheme.startsWith("http"))
        {
            return buildUrl(decodedUrl, decodedFragment);
        }

        URI uri = new URI(scheme, removeFragment(decodedUrl, decodedFragment), decodedFragment);
        StringBuilder result = new StringBuilder(uri.getRawSchemeSpecificPart());
        if (decodedFragment != null)
        {
            result.append(FRAGMENT_SEPARATOR).append(uri.getRawFragment());
        }
        return URI.create(result.toString());
    }
    catch (URISyntaxException | MalformedURLException e)
    {
        throw new IllegalArgumentException(e);
    }
}
 
Example 16
Source File: URIBuilder.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery());
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}
 
Example 17
Source File: ClassUsageTracker.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void onFileRead(FileObject fileObject) {
  if (!(fileObject instanceof JavaFileObject)) {
    return;
  }
  JavaFileObject javaFileObject = (JavaFileObject) fileObject;

  URI classFileJarUri = javaFileObject.toUri();
  if (!classFileJarUri.getScheme().equals(JAR_SCHEME)) {
    // Not in a jar; must not have been built with java_library
    return;
  }

  // The jar: scheme is somewhat underspecified. See the JarURLConnection docs
  // for the closest thing it has to documentation.
  String jarUriSchemeSpecificPart = classFileJarUri.getRawSchemeSpecificPart();
  String[] split = jarUriSchemeSpecificPart.split("!/");
  Preconditions.checkState(split.length == 2);

  if (isLocalOrAnonymousClass(split[1])) {
    // The compiler reads local and anonymous classes because of the naive way in which it
    // completes the enclosing class, but changes to them can't affect compilation of dependent
    // classes so we don't need to consider them "used".
    return;
  }

  URI jarFileUri = URI.create(split[0]);
  Preconditions.checkState(
      jarFileUri.getScheme().equals(FILE_SCHEME)
          || jarFileUri.getScheme().equals(JIMFS_SCHEME)); // jimfs is used in tests
  Path jarFilePath = Paths.get(jarFileUri);

  // Using URI.create here for de-escaping
  Path classPath = Paths.get(URI.create(split[1]).toString());

  Preconditions.checkState(jarFilePath.isAbsolute());
  Preconditions.checkState(!classPath.isAbsolute());
  resultBuilder.put(jarFilePath, classPath);
}
 
Example 18
Source File: JavaTypeSchema.java    From hypergraphdb with Apache License 2.0 4 votes vote down vote up
public static String uriToClassName(URI uri)
{
    return uri.getRawSchemeSpecificPart();
}
 
Example 19
Source File: EmoUriBuilder.java    From emodb with Apache License 2.0 4 votes vote down vote up
@Override
public UriBuilder schemeSpecificPart(String ssp) {
    if (ssp == null) {
        throw new IllegalArgumentException("Scheme specific part parameter is null");
    }

    // TODO encode or validate scheme specific part
    // This will not work for template variables present in the spp
    StringBuilder sb = new StringBuilder();
    if (scheme != null) {
        sb.append(scheme).append(':');
    }
    if (ssp != null) {
        sb.append(ssp);
    }
    if (fragment != null && fragment.length() > 0) {
        sb.append('#').append(fragment);
    }
    URI uri = createURI(sb.toString());

    if (uri.getRawSchemeSpecificPart() != null && uri.getRawPath() == null) {
        this.ssp = uri.getRawSchemeSpecificPart();
    } else {
        this.ssp = null;

        if (uri.getRawAuthority() != null) {
            if (uri.getRawUserInfo() == null && uri.getHost() == null && uri.getPort() == -1) {
                authority = uri.getRawAuthority();
                userInfo = null;
                host = null;
                port = -1;
            } else {
                authority = null;
                userInfo = uri.getRawUserInfo();
                host = uri.getHost();
                port = uri.getPort();
            }
        }

        path.setLength(0);
        path.append(replaceNull(uri.getRawPath()));

        query.setLength(0);
        query.append(replaceNull(uri.getRawQuery()));
    }
    return this;
}
 
Example 20
Source File: UriBuilderImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
private boolean schemeSpecificPartMatchesUriPath(final URI uri) {
    return uri.getRawSchemeSpecificPart() != null
            && uri.getPath() != null
            && uri.getRawSchemeSpecificPart().equals("//" + uri.getPath());
}