Example usage for java.net URI getScheme

List of usage examples for java.net URI getScheme

Introduction

In this page you can find the example usage for java.net URI getScheme.

Prototype

public String getScheme() 

Source Link

Document

Returns the scheme component of this URI.

Usage

From source file:com.anrisoftware.globalpom.checkfilehash.CheckFileHash.java

private String readExpectedHash(URI hashResource) throws Exception {
    if (StringUtils.equals(hashResource.getScheme(), "md5")) {
        return hashResource.getSchemeSpecificPart();
    } else if (StringUtils.equals(hashResource.getScheme(), "sha1")) {
        return hashResource.getSchemeSpecificPart();
    } else {//ww w  . jav  a2  s. c  o  m
        String line = readLines(hashResource.toURL().openStream()).get(0);
        String hash = StringUtils.split(line, SEP)[0];
        return hash;
    }
}

From source file:ch.cyberduck.core.cdn.DistributionUrlProvider.java

/**
 * @param file   File in origin container
 * @param origin Distribution URL/* w w  w.  j  a  v  a 2  s .c o m*/
 * @return URL to file in distribution
 */
private URI toUrl(final Path file, final URI origin) {
    final StringBuilder b = new StringBuilder(String.format("%s://%s", origin.getScheme(), origin.getHost()));
    if (distribution.getMethod().equals(Distribution.CUSTOM)) {
        b.append(Path.DELIMITER)
                .append(URIEncoder.encode(PathRelativizer.relativize(origin.getRawPath(), file.getAbsolute())));
    } else {
        if (StringUtils.isNotEmpty(origin.getRawPath())) {
            b.append(origin.getRawPath());
        }
        if (StringUtils.isNotEmpty(containerService.getKey(file))) {
            b.append(Path.DELIMITER).append(URIEncoder.encode(containerService.getKey(file)));
        }
    }
    return URI.create(b.toString()).normalize();
}

From source file:ddf.registry.server.rest.internal.RestRegistryServer.java

/**
 * Combines the URI and relative URL to form a full URL for external clients to use.
 *
 * @param registryUri URI from the calling context
 * @param relativeUrl URL Relative URL for a service
 * @return Absolute URL for the service//  w w w . ja  va2 s. c om
 */
private String combineUrl(URI registryUri, String relativeUrl) {
    StringBuilder serviceUrl = new StringBuilder();
    serviceUrl.append(registryUri.getScheme());
    serviceUrl.append("://");
    serviceUrl.append(registryUri.getHost());
    serviceUrl.append(":");
    serviceUrl.append(registryUri.getPort());
    serviceUrl.append(relativeUrl);
    return serviceUrl.toString();
}

From source file:org.jnode.jersey.JNContainer.java

private String getServerAddress(final URI baseUri) throws URISyntaxException {
    return new URI(baseUri.getScheme(), null, baseUri.getHost(), baseUri.getPort(), null, null, null)
            .toString();//  w w  w . j a  v a2  s  . c o  m
}

From source file:com.adobe.acs.commons.replication.impl.AgentHostsImpl.java

@Override
public final List<String> getHosts(final AgentFilter agentFilter) {
    final List<String> hosts = new ArrayList<String>();
    final Map<String, Agent> agents = agentManager.getAgents();

    for (final Agent agent : agents.values()) {
        if (!agentFilter.isIncluded(agent)) {
            continue;
        }/*  ww  w . j  a  va  2s .c  om*/

        try {
            final URI uri = new URI(agent.getConfiguration().getTransportURI());

            String tmp = StringUtils.defaultIfEmpty(uri.getScheme(), DEFAULT_SCHEME) + "://" + uri.getHost();
            if (uri.getPort() > 0) {
                tmp += ":" + uri.getPort();
            }

            hosts.add(tmp);
        } catch (URISyntaxException e) {
            log.error("Unable to extract a scheme/host/port from Agent transport URI [ {} ]",
                    agent.getConfiguration().getTransportURI());
        }
    }

    return hosts;
}

From source file:org.mobicents.servlet.restcomm.http.client.HttpRequestDescriptor.java

private URI base(final URI uri) {
    try {/*  ww  w  . j a va  2  s. c  om*/
        URIBuilder uriBuilder = new URIBuilder();
        uriBuilder.setScheme(uri.getScheme());
        uriBuilder.setHost(uri.getHost());
        uriBuilder.setPort(uri.getPort());
        uriBuilder.setPath(uri.getPath());

        if (uri.getUserInfo() != null) {
            uriBuilder.setUserInfo(uri.getUserInfo());
        }
        return uriBuilder.build();
    } catch (final URISyntaxException ignored) {
        // This should never happen since we are using a valid URI to construct ours.
        return null;
    }
}

From source file:com.hp.autonomy.hod.client.api.authentication.AuthenticationServiceImplTest.java

private void checkCombinedUrl(final SignedRequest request, final List<NameValuePair> expectedParameters)
        throws URISyntaxException {
    final URI uri = new URI(request.getUrl());
    assertThat(uri.getScheme() + "://" + uri.getHost(), is(ENDPOINT));
    assertThat(uri.getPath(), is(COMBINED_PATH));

    final List<NameValuePair> pairs = URLEncodedUtils.parse(uri, "UTF-8");
    assertThat(pairs, containsInAnyOrder(expectedParameters.toArray()));
}

From source file:gov.nih.nci.iso21090.Tel.java

/**
 * @param value the value to set/*  w w  w. j ava  2s  .  c  o m*/
 */
public void setValue(URI value) {

    if (!isAllowed(value, getAllowedSchemes())) {
        throw new IllegalArgumentException(value.getScheme());
    }
    this.value = value;
}

From source file:com.microsoft.tfs.core.util.URIUtils.java

/**
 * Ensures that the specified {@link URI} has any trailing slashes REMOVED.
 * VisualStudio uses server URIs that lack trailing slashes, this is for
 * compatibility. However, a path of only / will be maintained.
 *
 * @param uri/*from   ww  w  .j a  v  a  2  s. c o  m*/
 *        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 removeTrailingSlash(final URI uri) {
    Check.notNull(uri, "uri"); //$NON-NLS-1$

    if (uri.isOpaque()) {
        return uri;
    }

    String path = uri.getPath();

    if (path == null) {
        path = "/"; //$NON-NLS-1$
    } else if (!path.equals("/")) //$NON-NLS-1$
    {
        while (path.endsWith("/")) //$NON-NLS-1$
        {
            path = path.substring(0, path.length() - 1);
        }
    }

    return newURI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(), uri.getFragment());
}

From source file:com.buaa.cfs.fs.AbstractFileSystem.java

/**
 * Create a file system instance for the specified uri using the conf. The conf is used to find the class name that
 * implements the file system. The conf is also passed to the file system for its configuration.
 *
 * @param uri  URI of the file system//from  w  w  w  . jav  a  2  s  .c o m
 * @param conf Configuration for the file system
 *
 * @return Returns the file system for the given URI
 *
 * @throws UnsupportedFileSystemException file system for <code>uri</code> is not found
 */
public static AbstractFileSystem createFileSystem(URI uri, Configuration conf)
        throws UnsupportedFileSystemException {
    final String fsImplConf = String.format("fs.AbstractFileSystem.%s.impl", uri.getScheme());

    Class<?> clazz = conf.getClass(fsImplConf, null);
    if (clazz == null) {
        throw new UnsupportedFileSystemException(
                String.format("%s=null: %s: %s", fsImplConf, NO_ABSTRACT_FS_ERROR, uri.getScheme()));
    }
    return (AbstractFileSystem) newInstance(clazz, uri, conf);
}