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.amazon.s3.util.HttpUtils.java

/**
 * Returns true if the specified URI is using a non-standard port (i.e. any
 * port other than 80 for HTTP URIs or any port other than 443 for HTTPS
 * URIs).//w  w w.j  av  a 2  s .com
 * 
 * @param uri
 * 
 * @return True if the specified URI is using a non-standard port, otherwise
 *         false.
 */
public static boolean isUsingNonDefaultPort(URI uri) {
    String scheme = uri.getScheme().toLowerCase();
    int port = uri.getPort();

    if (port <= 0)
        return false;
    if (scheme.equals("http") && port == 80)
        return false;
    if (scheme.equals("https") && port == 443)
        return false;

    return true;
}

From source file:net.sf.ufsc.SessionFactory.java

/**
 * Returns a session for the file server indicated by the specified URI.
 * @param uri a URI/*from   w w  w  . ja  v  a 2 s .co  m*/
 * @return a file server session
 * @throws java.io.IOException if uri scheme is invalid, or a session could not be obtained for this file server defined by the specified URI.
 */
public static Session getSession(URI uri) throws java.io.IOException {
    return instance.getProvider(uri.getScheme()).createSession(uri);
}

From source file:de.lohndirekt.print.IppHttpConnection.java

private static URI toHttpURI(URI uri) {
    if (uri.getScheme().equals("ipp")) {
        String uriString = uri.toString().replaceFirst("ipp", "http");
        // TODO remove this hack!
        //            uriString = uriString.replaceAll("(\\d{1,3}\\.){3}\\d{1,3}:\\d{1,}", "127.0.0.1:631");
        // endof hack
        try {//w w  w  .j av  a 2  s .  co  m
            uri = new URI(uriString);
        } catch (URISyntaxException e) {
            throw new RuntimeException("toHttpURI buggy? : uri was " + uri);
        }
    }
    return uri;
}

From source file:at.bitfire.davdroid.URIUtils.java

/**
 * Parse a received absolute/relative URL and generate a normalized URI that can be compared.
 * @param original       URI to be parsed, may be absolute or relative
  * @param mustBePath    true if it's known that original is a path (may contain ":") and not an URI, i.e. ":" is not the scheme separator
 * @return             normalized URI//from w ww  .  java 2  s.c  om
 * @throws URISyntaxException
 */
public static URI parseURI(String original, boolean mustBePath) throws URISyntaxException {
    if (mustBePath) {
        // may contain ":"
        // case 1: "my:file"        won't be parsed by URI correctly because it would consider "my" as URI scheme
        // case 2: "path/my:file"   will be parsed by URI correctly
        // case 3: "my:path/file"   won't be parsed by URI correctly because it would consider "my" as URI scheme
        int idxSlash = original.indexOf('/'), idxColon = original.indexOf(':');
        if (idxColon != -1) {
            // colon present
            if ((idxSlash != -1) && idxSlash < idxColon) // There's a slash, and it's before the colon  everything OK
                ;
            else // No slash before the colon; we have to put it there
                original = "./" + original;
        }
    }

    // escape some common invalid characters  servers keep sending unescaped crap like "my calendar.ics" or "{guid}.vcf"
    // this is only a hack, because for instance, "[" may be valid in URLs (IPv6 literal in host name)
    String repaired = original.replaceAll(" ", "%20").replaceAll("\\{", "%7B").replaceAll("\\}", "%7D");
    if (!repaired.equals(original))
        Log.w(TAG, "Repaired invalid URL: " + original + " -> " + repaired);

    URI uri = new URI(repaired);
    URI normalized = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(),
            uri.getFragment());
    Log.v(TAG, "Normalized URL " + original + " -> " + normalized.toASCIIString());
    return normalized;
}

From source file:com.google.mr4c.content.RelativeContentFactory.java

public static File toFile(URI uri, File parent) {
    if (!"rel".equals(uri.getScheme())) {
        throw new IllegalArgumentException("Expecting a relative file URI [" + uri + "]");
    }//  w  w  w .  j a v  a2  s.c  o m
    // Doing this because File won't take a URI with a relative path
    String path = uri.getSchemeSpecificPart();
    return new File(parent, path);
}

From source file:com.xx_dev.apn.proxy.utils.HostNamePortUtil.java

public static String getHostName(HttpRequest httpRequest) {
    String originalHostHeader = httpRequest.headers().get(HttpHeaders.Names.HOST);

    if (StringUtils.isBlank(originalHostHeader) && httpRequest.getMethod().equals(HttpMethod.CONNECT)) {
        originalHostHeader = httpRequest.getUri();
    }//  ww w .jav a  2s  . c o m

    if (StringUtils.isNotBlank(originalHostHeader)) {
        String originalHost = StringUtils.split(originalHostHeader, ": ")[0];
        return originalHost;
    } else {
        String uriStr = httpRequest.getUri();
        try {
            URI uri = new URI(uriStr);

            String schema = uri.getScheme();

            String originalHost = uri.getHost();

            return originalHost;
        } catch (URISyntaxException e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }
}

From source file:com.blackducksoftware.integration.hub.util.HubUrlParser.java

public static String getBaseUrl(final String url) throws URISyntaxException {
    final URI uri = new URI(url);
    final String derivedUrlPrefix = StringUtils.join(uri.getScheme(), "://", uri.getAuthority(), "/");
    return derivedUrlPrefix;
}

From source file:gobblin.util.JobConfigurationUtils.java

/**
 * Load the properties from the specified file into a {@link Properties} object.
 *
 * @param fileName the name of the file to load properties from
 * @param conf configuration object to determine the file system to be used
 * @return a new {@link Properties} instance
 *///from w  ww  .  j a  v  a  2 s  .  c  o  m
public static Properties fileToProperties(String fileName, Configuration conf)
        throws IOException, ConfigurationException {

    PropertiesConfiguration propsConfig = new PropertiesConfiguration();
    Path filePath = new Path(fileName);
    URI fileURI = filePath.toUri();

    if (fileURI.getScheme() == null && fileURI.getAuthority() == null) {
        propsConfig.load(FileSystem.getLocal(conf).open(filePath));
    } else {
        propsConfig.load(filePath.getFileSystem(conf).open(filePath));
    }
    return ConfigurationConverter.getProperties(propsConfig);
}

From source file:com.netdimensions.client.Client.java

private static HttpHost host(final URI url) {
    return new HttpHost(url.getHost(), url.getPort(), url.getScheme());
}

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

private static boolean isAllowed(URI uri, List<String> allowedSchemes) {
    return uri != null && isAllowed(uri.getScheme(), allowedSchemes);
}