Example usage for java.net URI getAuthority

List of usage examples for java.net URI getAuthority

Introduction

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

Prototype

public String getAuthority() 

Source Link

Document

Returns the decoded authority component of this URI.

Usage

From source file:de.vandermeer.skb.datatool.commons.DataUtilities.java

/**
 * Loads an data for an SKB link.//from  w  w  w . jav a2s  .  c o  m
 * @param skbLink the link to load an data for
 * @param loadedTypes loaded types as lookup for links
 * @return an object if successfully loaded, null otherwise
 * @throws IllegalArgumentException if any of the required arguments or map entries are not set or empty
 * @throws URISyntaxException if creating a URI for an SKB link failed
 */
public static Object loadLink(Object skbLink, LoadedTypeMap loadedTypes) throws URISyntaxException {
    if (skbLink == null) {
        throw new IllegalArgumentException("skb link null");
    }
    if (loadedTypes == null) {
        throw new IllegalArgumentException("trying to load a link, but no loaded types given");
    }

    URI uri = new URI(skbLink.toString());
    if (!"skb".equals(uri.getScheme())) {
        throw new IllegalArgumentException("unknown scheme in link <" + skbLink + ">");
    }

    String uriReq = uri.getScheme() + "://" + uri.getAuthority();
    DataEntryType type = null;
    for (DataEntryType det : loadedTypes.keySet()) {
        if (uriReq.equals(det.getLinkUri())) {
            type = det;
            break;
        }
    }
    if (type == null) {
        throw new IllegalArgumentException(
                "no data entry type for link <" + uri.getScheme() + "://" + uri.getAuthority() + ">");
    }

    @SuppressWarnings("unchecked")
    Map<String, Object> map = (Map<String, Object>) loadedTypes.getTypeMap(type);
    if (map == null) {
        throw new IllegalArgumentException("no entry for type <" + type.getType() + "> in link map");
    }

    String key = StringUtils.substringAfterLast(uri.getPath(), "/");
    Object ret = map.get(key);
    if (ret == null) {
        throw new IllegalArgumentException(
                "no entry for <" + uri.getAuthority() + "> key <" + key + "> in link map");
    }
    return ret;
}

From source file:org.apache.hadoop.security.ProviderUtils.java

/**
 * Mangle given local java keystore file URI to allow use as a
 * LocalJavaKeyStoreProvider.//from w  ww.  j  ava 2 s. c  om
 * @param localFile absolute URI with file scheme and no authority component.
 *                  i.e. return of File.toURI,
 *                  e.g. file:///home/larry/creds.jceks
 * @return URI of the form localjceks://file/home/larry/creds.jceks
 * @throws IllegalArgumentException if localFile isn't not a file uri or if it
 *                                  has an authority component.
 * @throws URISyntaxException if the wrapping process violates RFC 2396
 */
public static URI nestURIForLocalJavaKeyStoreProvider(final URI localFile) throws URISyntaxException {
    if (!("file".equals(localFile.getScheme()))) {
        throw new IllegalArgumentException("passed URI had a scheme other than " + "file.");
    }
    if (localFile.getAuthority() != null) {
        throw new IllegalArgumentException(
                "passed URI must not have an " + "authority component. For non-local keystores, please use "
                        + JavaKeyStoreProvider.class.getName());
    }
    return new URI(LocalJavaKeyStoreProvider.SCHEME_NAME, "//file" + localFile.getSchemeSpecificPart(),
            localFile.getFragment());
}

From source file:org.apache.hadoop.hive.ql.exec.ArchiveUtils.java

/**
 * Makes sure, that URI points to directory by adding slash to it.
 * Useful in relativizing URIs.// ww  w  . j a v  a2 s.c o m
 */
public static URI addSlash(URI u) throws HiveException {
    if (u.getPath().endsWith("/")) {
        return u;
    } else {
        try {
            return new URI(u.getScheme(), u.getAuthority(), u.getPath() + "/", u.getQuery(), u.getFragment());
        } catch (URISyntaxException e) {
            throw new HiveException("Couldn't append slash to a URI", e);
        }
    }
}

From source file:org.apache.ignite.internal.processors.hadoop.igfs.HadoopIgfsEndpoint.java

/**
 * Normalize IGFS URI.// w ww.  ja v  a2s. c o m
 *
 * @param uri URI.
 * @return Normalized URI.
 * @throws IOException If failed.
 */
public static URI normalize(URI uri) throws IOException {
    try {
        if (!F.eq(IgniteFileSystem.IGFS_SCHEME, uri.getScheme()))
            throw new IOException("Failed to normalize UIR because it has non IGFS scheme: " + uri);

        HadoopIgfsEndpoint endpoint = new HadoopIgfsEndpoint(uri.getAuthority());

        StringBuilder sb = new StringBuilder();

        if (endpoint.igfs() != null)
            sb.append(endpoint.igfs());

        return new URI(uri.getScheme(), sb.length() != 0 ? sb.toString() : null, endpoint.host(),
                endpoint.port(), uri.getPath(), uri.getQuery(), uri.getFragment());
    } catch (URISyntaxException | IgniteCheckedException e) {
        throw new IOException("Failed to normalize URI: " + uri, e);
    }
}

From source file:org.fcrepo.apix.jena.impl.JenaServiceRegistry.java

private static boolean hasSameRepresentation(final URI a, final URI b) {
    try {//from  w ww  .  j  a va 2  s.c  o  m
        return new URI(a.getScheme(), a.getAuthority(), a.getPath(), null, null)
                .equals(new URI(b.getScheme(), b.getAuthority(), b.getPath(), null, null));
    } catch (final URISyntaxException e) {
        throw new RuntimeException("Shoud never happen", e);
    }
}

From source file:org.apache.spark.sql.parser.SemanticAnalyzer.java

public static String relativeToAbsolutePath(HiveConf conf, String location) throws SemanticException {
    boolean testMode = conf.getBoolVar(HiveConf.ConfVars.HIVETESTMODE);
    if (testMode) {
        URI uri = new Path(location).toUri();
        String scheme = uri.getScheme();
        String authority = uri.getAuthority();
        String path = uri.getPath();
        if (!path.startsWith("/")) {
            path = (new Path(System.getProperty("test.tmp.dir"), path)).toUri().getPath();
        }/* www  . ja v  a2 s.c  o  m*/
        if (StringUtils.isEmpty(scheme)) {
            scheme = "pfile";
        }
        try {
            uri = new URI(scheme, authority, path, null, null);
        } catch (URISyntaxException e) {
            throw new SemanticException(ErrorMsg.INVALID_PATH.getMsg(), e);
        }
        return uri.toString();
    } else {
        //no-op for non-test mode for now
        return location;
    }
}

From source file:com.igormaznitsa.mindmap.model.ModelUtils.java

@Nonnull
public static File toFile(@Nonnull final URI uri) {
    final List<String> pathItems = new ArrayList<String>();

    final String authority = uri.getAuthority();
    if (authority != null && !authority.isEmpty()) {
        pathItems.add(authority);/*w w  w .  j  a v  a2 s .co  m*/
    }

    final String[] splittedPath = uri.getPath().split("\\/");
    boolean separator = false;
    if (splittedPath.length == 0) {
        separator = true;
    } else {
        for (final String s : splittedPath) {
            if (!s.isEmpty()) {
                pathItems.add(separator ? File.separatorChar + s : s);
                separator = false;
            } else {
                separator = true;
            }
        }
    }

    if (separator) {
        pathItems.add(File.separator);
    }

    final String[] fullArray = pathItems.toArray(new String[pathItems.size()]);
    final String[] next = Arrays.copyOfRange(fullArray, 1, fullArray.length);
    return Paths.get(fullArray[0], next).toFile();
}

From source file:edu.stolaf.cs.wmrserver.JobServiceHandler.java

/**
 * Relativize the given path with respect to the WMR home directory
 *///w w w.j  a v  a 2  s.c  o  m
public static Path relativizePath(Path parentPath, Path childPath) {
    URI relative = parentPath.toUri().relativize(childPath.toUri());
    return new Path(relative.getScheme(), relative.getAuthority(), relative.getPath());
}

From source file:org.apache.hadoop.security.SecurityUtil.java

/**
 * create the service name for a Delegation token
 * @param uri of the service/* w ww . j  ava 2  s  .c o  m*/
 * @param defPort is used if the uri lacks a port
 * @return the token service, or null if no authority
 * @see #buildTokenService(InetSocketAddress)
 */
public static String buildDTServiceName(URI uri, int defPort) {
    String authority = uri.getAuthority();
    if (authority == null || authority.isEmpty()) {
        return null;
    }
    InetSocketAddress addr = NetUtils.createSocketAddr(authority, defPort);
    return buildTokenService(addr).toString();
}

From source file:com.google.u2f.server.impl.U2FServerReferenceImpl.java

static String canonicalizeOrigin(String url) {
    URI uri;
    try {//from w ww.j  av  a 2  s  .  c  o  m
        uri = new URI(url);
    } catch (URISyntaxException e) {
        throw new RuntimeException("specified bad origin", e);
    }
    return uri.getScheme() + "://" + uri.getAuthority();
}