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

The following examples show how to use java.net.URI#getRawAuthority() . 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: SMBOperationHandler.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static String decodeURI(URI fileUri) {
	 // decode %-encoding in everything except authority
	StringBuilder sb = new StringBuilder();
	if (fileUri.getScheme() != null) {
		sb.append(fileUri.getScheme()).append("://");
	}
	if (fileUri.getRawAuthority() != null) {
		sb.append(fileUri.getRawAuthority());
	}
	sb.append(fileUri.getPath());
	if (fileUri.getQuery() != null) {
		sb.append('?').append(fileUri.getQuery());
	}
	if (fileUri.getFragment() != null) {
		sb.append('#').append(fileUri.getFragment());
	}
	return sb.toString();
}
 
Example 2
Source File: SourceIdentifiers.java    From es6draft with MIT License 6 votes vote down vote up
private static boolean hasIllegalComponents(URI moduleName) {
    // All components except for 'path' must be empty.
    if (moduleName.getScheme() != null) {
        return true;
    }
    if (moduleName.getRawAuthority() != null) {
        return true;
    }
    if (moduleName.getRawUserInfo() != null) {
        return true;
    }
    if (moduleName.getHost() != null) {
        return true;
    }
    if (moduleName.getPort() != -1) {
        return true;
    }
    if (moduleName.getRawQuery() != null) {
        return true;
    }
    if (moduleName.getRawFragment() != null) {
        return true;
    }
    return false;
}
 
Example 3
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 4
Source File: ArmeriaClientHttpConnector.java    From armeria with Apache License 2.0 6 votes vote down vote up
private ArmeriaClientHttpRequest createRequest(HttpMethod method, URI uri) {
    final String scheme = uri.getScheme();
    final String authority = uri.getRawAuthority();
    final String path = uri.getRawPath();
    final String query = uri.getRawQuery();

    checkArgument(!Strings.isNullOrEmpty(authority), "URI is not absolute: %s", uri);
    checkArgument(!Strings.isNullOrEmpty(path), "path is undefined: %s", uri);

    final URI baseUri = URI.create(Strings.isNullOrEmpty(scheme) ? authority : scheme + "://" + authority);
    final WebClientBuilder builder = WebClient.builder(baseUri);
    configurators.forEach(c -> c.configure(builder));

    final String pathAndQuery = Strings.isNullOrEmpty(query) ? path : path + '?' + query;

    return new ArmeriaClientHttpRequest(builder.build(), method, pathAndQuery, uri, factoryWrapper);
}
 
Example 5
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 6
Source File: UnixFileSystemProvider.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void checkUri(URI uri) {
    if (!uri.getScheme().equalsIgnoreCase(getScheme()))
        throw new IllegalArgumentException("URI does not match this provider");
    if (uri.getRawAuthority() != null)
        throw new IllegalArgumentException("Authority component present");
    String path = uri.getPath();
    if (path == null)
        throw new IllegalArgumentException("Path component is undefined");
    if (!path.equals("/"))
        throw new IllegalArgumentException("Path component should be '/'");
    if (uri.getRawQuery() != null)
        throw new IllegalArgumentException("Query component present");
    if (uri.getRawFragment() != null)
        throw new IllegalArgumentException("Fragment component present");
}
 
Example 7
Source File: ParsingThread.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
private static boolean sameSchemeAuthority(final byte[] schemeAuthority, final URI url) {
	final String scheme = url.getScheme();
	int schemeLength = scheme.length();
	if (schemeAuthority.length < schemeLength + 3) return false;
	for(int i = schemeLength; i-- != 0;) if (schemeAuthority[i] != (byte)scheme.charAt(i)) return false;
	if (schemeAuthority[schemeLength++] != (byte)':') return false;
	if (schemeAuthority[schemeLength++] != (byte)'/') return false;
	if (schemeAuthority[schemeLength++] != (byte)'/') return false;

	final String authority = url.getRawAuthority();
	if (schemeAuthority.length != schemeLength + authority.length()) return false;
	for(int i = authority.length(); i-- != 0;) if (schemeAuthority[schemeLength + i] != (byte)authority.charAt(i)) return false;
	return true;
}
 
Example 8
Source File: URIBuilder.java    From BigApp_Discuz_Android 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 9
Source File: ConnectionUrlParser.java    From r2dbc-spi with Apache License 2.0 4 votes vote down vote up
static ConnectionFactoryOptions parseQuery(CharSequence url) {

        String urlToUse = url.toString();
        validate(urlToUse);

        // R2DBC URL must contain at least two colons in the scheme part (r2dbc:<some driver>:).
        String[] schemeParts = urlToUse.split(":", 3);

        String scheme = schemeParts[0];
        String driver = schemeParts[1];
        String protocol = schemeParts[2];

        int schemeSpecificPartIndex = urlToUse.indexOf("://");
        String rewrittenUrl = scheme + urlToUse.substring(schemeSpecificPartIndex);

        URI uri = URI.create(rewrittenUrl);

        ConnectionFactoryOptions.Builder builder = ConnectionFactoryOptions.builder();

        if (scheme.equals(R2DBC_SSL_SCHEME)) {
            builder.option(ConnectionFactoryOptions.SSL, true);
        }

        builder.option(ConnectionFactoryOptions.DRIVER, driver);

        int protocolEnd = protocol.indexOf("://");
        if (protocolEnd != -1) {
            protocol = protocol.substring(0, protocolEnd);

            if (!protocol.trim().isEmpty()) {
                builder.option(ConnectionFactoryOptions.PROTOCOL, protocol);
            }
        }

        if (hasText(uri.getHost())) {
            builder.option(ConnectionFactoryOptions.HOST, decode(uri.getHost().trim()).toString());

            if (hasText(uri.getRawUserInfo())) {
                parseUserinfo(uri.getRawUserInfo(), builder);
            }
        } else if (hasText(uri.getRawAuthority())) {

            String authorityToUse = uri.getRawAuthority();

            if (authorityToUse.contains("@")) {

                int atIndex = authorityToUse.indexOf('@');
                String userinfo = authorityToUse.substring(0, atIndex);
                authorityToUse = authorityToUse.substring(atIndex + 1);

                if (!userinfo.isEmpty()) {
                    parseUserinfo(userinfo, builder);
                }
            }

            builder.option(ConnectionFactoryOptions.HOST, decode(authorityToUse.trim()).toString());
        }

        if (uri.getPort() != -1) {
            builder.option(ConnectionFactoryOptions.PORT, uri.getPort());
        }

        if (hasText(uri.getPath())) {
            String path = uri.getPath().substring(1).trim();
            if (hasText(path)) {
                builder.option(ConnectionFactoryOptions.DATABASE, path);
            }
        }

        if (hasText(uri.getRawQuery())) {
            parseQuery(uri.getRawQuery().trim(), (k, v) -> {

                if (PROHIBITED_QUERY_OPTIONS.contains(k)) {
                    throw new IllegalArgumentException(
                        String.format("URL %s must not declare option %s in the query string", url, k));
                }

                builder.option(Option.valueOf(k), v);
            });
        }

        return builder.build();
    }
 
Example 10
Source File: HttpRequest.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
public HttpRequest(
  String method,
  String url,
  LinkedListMultimap<String, String> headers,
  String body,
  String server,
  LinkedListMultimap<String, String> queryParameters
) {
  if (url != null) {
    URI uri = URI.create(url);
    if (uri.isOpaque()) {
      throw new IllegalArgumentException("Should be a URL, not a URI");
    }
    this.path = uri.getPath();
    if (uri.isAbsolute() && server == null) {
      this.server = uri.getScheme() + "://" + uri.getRawAuthority();
    } else {
      this.server = server;
    }
    //if you have query parameters in the base url _and_ separate query parameters then the result is a concatenation
    if (uri.getRawQuery() != null) {
      this.queryParameters = LinkedListMultimap.create();
      for (String querySegment : Splitter.on("&").split(uri.getRawQuery())) {
        int equalsLocation = querySegment.indexOf('=');
        String key = querySegment.substring(0, equalsLocation);
        String value = querySegment.substring(equalsLocation + 1);
        this.queryParameters.put(key, value);
      }
      if (queryParameters != null) {
        this.queryParameters.putAll(queryParameters);
      }
    } else {
      this.queryParameters = queryParameters;
    }
  } else {
    this.server = server;
    this.path = "";
    this.queryParameters = queryParameters;
  }
  this.method = method;
  this.headers = headers;
  this.body = body;
}
 
Example 11
Source File: ClientFactory.java    From armeria with Apache License 2.0 4 votes vote down vote up
/**
 * Makes sure the specified {@link URI} is supported by this {@link ClientFactory}.
 *
 * @param uri the {@link URI} of the server endpoint
 * @return the validated and normalized {@link URI} which always has a non-empty path.
 *
 * @throws IllegalArgumentException if the scheme of the specified {@link URI} is not supported by this
 *                                  {@link ClientFactory}
 */
default URI validateUri(URI uri) {
    requireNonNull(uri, "uri");

    if (Clients.isUndefinedUri(uri)) {
        // We use a special singleton marker URI for clients that do not explicitly define a
        // host or scheme at construction time.
        // As this isn't created by users, we don't need to normalize it.
        return uri;
    }

    if (uri.getAuthority() == null) {
        throw new IllegalArgumentException("URI with missing authority: " + uri);
    }

    final String scheme = uri.getScheme();
    if (scheme == null) {
        throw new IllegalArgumentException("URI with missing scheme: " + uri);
    }
    final Scheme parsedScheme = Scheme.tryParse(scheme);
    if (parsedScheme == null) {
        throw new IllegalArgumentException("URI with undefined scheme: " + uri);
    }

    final Set<Scheme> supportedSchemes = supportedSchemes();
    if (!supportedSchemes.contains(parsedScheme)) {
        throw new IllegalArgumentException(
                "URI with unsupported scheme: " + uri + " (expected: " + supportedSchemes + ')');
    }

    final String parsedSchemeStr;
    if (parsedScheme.serializationFormat() == SerializationFormat.NONE) {
        parsedSchemeStr = parsedScheme.sessionProtocol().uriText();
    } else {
        parsedSchemeStr = parsedScheme.uriText();
    }

    final String path = Strings.emptyToNull(uri.getRawPath());
    if (scheme.equals(parsedSchemeStr) && path != null) {
        return uri;
    }

    // Replace the specified URI's scheme with the normalized one.
    try {
        return new URI(parsedSchemeStr, uri.getRawAuthority(),
                       firstNonNull(path, "/"), uri.getRawQuery(),
                       uri.getRawFragment());
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
Example 12
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 13
Source File: AzureNativeFileSystemStore.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Method to extract the container name from an Azure URI.
 * 
 * @param uri
 *          -- WASB blob URI
 * @returns containerName -- the container name for the URI. May be null.
 * @throws URISyntaxException
 *           if the uri does not have an authority it is badly formed.
 */
private String getContainerFromAuthority(URI uri) throws URISyntaxException {

  // Check to make sure that the authority is valid for the URI.
  //
  String authority = uri.getRawAuthority();
  if (null == authority) {
    // Badly formed or illegal URI.
    //
    throw new URISyntaxException(uri.toString(),
        "Expected URI with a valid authority");
  }

  // The URI has a valid authority. Extract the container name. It is the
  // second component of the WASB URI authority.
  if (!authority.contains(WASB_AUTHORITY_DELIMITER)) {
    // The authority does not have a container name. Use the default container by
    // setting the container name to the default Azure root container.
    //
    return AZURE_ROOT_CONTAINER;
  }

  // Split off the container name and the authority.
  String[] authorityParts = authority.split(WASB_AUTHORITY_DELIMITER, 2);

  // Because the string contains an '@' delimiter, a container must be
  // specified.
  if (authorityParts.length < 2 || "".equals(authorityParts[0])) {
    // Badly formed WASB authority since there is no container.
    final String errMsg = String
        .format(
            "URI '%s' has a malformed WASB authority, expected container name."
                + "Authority takes the form wasb://[<container name>@]<account name>",
            uri.toString());
    throw new IllegalArgumentException(errMsg);
  }

  // Set the container name from the first entry for the split parts of the
  // authority.
  return authorityParts[0];
}
 
Example 14
Source File: AzureNativeFileSystemStore.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Method to extract the account name from an Azure URI.
 * 
 * @param uri
 *          -- WASB blob URI
 * @returns accountName -- the account name for the URI.
 * @throws URISyntaxException
 *           if the URI does not have an authority it is badly formed.
 */
private String getAccountFromAuthority(URI uri) throws URISyntaxException {

  // Check to make sure that the authority is valid for the URI.
  //
  String authority = uri.getRawAuthority();
  if (null == authority) {
    // Badly formed or illegal URI.
    //
    throw new URISyntaxException(uri.toString(),
        "Expected URI with a valid authority");
  }

  // Check if authority container the delimiter separating the account name from the
  // the container.
  //
  if (!authority.contains(WASB_AUTHORITY_DELIMITER)) {
    return authority;
  }

  // Split off the container name and the authority.
  //
  String[] authorityParts = authority.split(WASB_AUTHORITY_DELIMITER, 2);

  // Because the string contains an '@' delimiter, a container must be
  // specified.
  //
  if (authorityParts.length < 2 || "".equals(authorityParts[0])) {
    // Badly formed WASB authority since there is no container.
    //
    final String errMsg = String
        .format(
            "URI '%s' has a malformed WASB authority, expected container name. "
                + "Authority takes the form wasb://[<container name>@]<account name>",
            uri.toString());
    throw new IllegalArgumentException(errMsg);
  }

  // Return with the account name. It is possible that this name is NULL.
  //
  return authorityParts[1];
}
 
Example 15
Source File: AzureNativeFileSystemStore.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Method to extract the container name from an Azure URI.
 * 
 * @param uri
 *          -- WASB blob URI
 * @returns containerName -- the container name for the URI. May be null.
 * @throws URISyntaxException
 *           if the uri does not have an authority it is badly formed.
 */
private String getContainerFromAuthority(URI uri) throws URISyntaxException {

  // Check to make sure that the authority is valid for the URI.
  //
  String authority = uri.getRawAuthority();
  if (null == authority) {
    // Badly formed or illegal URI.
    //
    throw new URISyntaxException(uri.toString(),
        "Expected URI with a valid authority");
  }

  // The URI has a valid authority. Extract the container name. It is the
  // second component of the WASB URI authority.
  if (!authority.contains(WASB_AUTHORITY_DELIMITER)) {
    // The authority does not have a container name. Use the default container by
    // setting the container name to the default Azure root container.
    //
    return AZURE_ROOT_CONTAINER;
  }

  // Split off the container name and the authority.
  String[] authorityParts = authority.split(WASB_AUTHORITY_DELIMITER, 2);

  // Because the string contains an '@' delimiter, a container must be
  // specified.
  if (authorityParts.length < 2 || "".equals(authorityParts[0])) {
    // Badly formed WASB authority since there is no container.
    final String errMsg = String
        .format(
            "URI '%s' has a malformed WASB authority, expected container name."
                + "Authority takes the form wasb://[<container name>@]<account name>",
            uri.toString());
    throw new IllegalArgumentException(errMsg);
  }

  // Set the container name from the first entry for the split parts of the
  // authority.
  return authorityParts[0];
}
 
Example 16
Source File: AzureNativeFileSystemStore.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Method to extract the account name from an Azure URI.
 * 
 * @param uri
 *          -- WASB blob URI
 * @returns accountName -- the account name for the URI.
 * @throws URISyntaxException
 *           if the URI does not have an authority it is badly formed.
 */
private String getAccountFromAuthority(URI uri) throws URISyntaxException {

  // Check to make sure that the authority is valid for the URI.
  //
  String authority = uri.getRawAuthority();
  if (null == authority) {
    // Badly formed or illegal URI.
    //
    throw new URISyntaxException(uri.toString(),
        "Expected URI with a valid authority");
  }

  // Check if authority container the delimiter separating the account name from the
  // the container.
  //
  if (!authority.contains(WASB_AUTHORITY_DELIMITER)) {
    return authority;
  }

  // Split off the container name and the authority.
  //
  String[] authorityParts = authority.split(WASB_AUTHORITY_DELIMITER, 2);

  // Because the string contains an '@' delimiter, a container must be
  // specified.
  //
  if (authorityParts.length < 2 || "".equals(authorityParts[0])) {
    // Badly formed WASB authority since there is no container.
    //
    final String errMsg = String
        .format(
            "URI '%s' has a malformed WASB authority, expected container name. "
                + "Authority takes the form wasb://[<container name>@]<account name>",
            uri.toString());
    throw new IllegalArgumentException(errMsg);
  }

  // Return with the account name. It is possible that this name is NULL.
  //
  return authorityParts[1];
}
 
Example 17
Source File: WindowsUriSupport.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts given URI to a Path
 */
static WindowsPath fromUri(WindowsFileSystem fs, URI uri) {
    if (!uri.isAbsolute())
        throw new IllegalArgumentException("URI is not absolute");
    if (uri.isOpaque())
        throw new IllegalArgumentException("URI is not hierarchical");
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
        throw new IllegalArgumentException("URI scheme is not \"file\"");
    if (uri.getRawFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getRawQuery() != null)
        throw new IllegalArgumentException("URI has a query component");
    String path = uri.getPath();
    if (path.equals(""))
        throw new IllegalArgumentException("URI path component is empty");

    // UNC
    String auth = uri.getRawAuthority();
    if (auth != null && !auth.equals("")) {
        String host = uri.getHost();
        if (host == null)
            throw new IllegalArgumentException("URI authority component has undefined host");
        if (uri.getUserInfo() != null)
            throw new IllegalArgumentException("URI authority component has user-info");
        if (uri.getPort() != -1)
            throw new IllegalArgumentException("URI authority component has port number");

        // IPv6 literal
        // 1. drop enclosing brackets
        // 2. replace ":" with "-"
        // 3. replace "%" with "s" (zone/scopeID delimiter)
        // 4. Append .ivp6-literal.net
        if (host.startsWith("[")) {
            host = host.substring(1, host.length()-1)
                       .replace(':', '-')
                       .replace('%', 's');
            host += IPV6_LITERAL_SUFFIX;
        }

        // reconstitute the UNC
        path = "\\\\" + host + path;
    } else {
        if ((path.length() > 2) && (path.charAt(2) == ':')) {
            // "/c:/foo" --> "c:/foo"
            path = path.substring(1);
        }
    }
    return WindowsPath.parse(fs, path);
}
 
Example 18
Source File: FastenURI.java    From fasten with Apache License 2.0 4 votes vote down vote up
protected FastenURI(URI uri) {
	if (uri.getScheme() != null && ! "fasten".equalsIgnoreCase(uri.getScheme())) throw new IllegalArgumentException("Scheme, if specified, must be 'fasten'");
	// Bypass URI when the scheme is specified, but there is no forge-product-version
	if (uri.isOpaque()) uri = URI.create(uri.getSchemeSpecificPart());

	this.uri = uri;
	final String forgeProductVersion = uri.getRawAuthority();

	if (forgeProductVersion == null) rawForge = rawProduct = rawVersion = null;
	else {
		final var exclPos = forgeProductVersion.indexOf('!');
		String productVersion;
		if (exclPos == -1) { // No forge
			rawForge = null;
			productVersion = forgeProductVersion;
		}
		else {
			rawForge = forgeProductVersion.substring(0,  exclPos);
			productVersion = forgeProductVersion.substring(exclPos + 1);
			if (productVersion.indexOf('!') >= 0) throw new IllegalArgumentException("More than one forge");
		}

                     this.validateRawForge();

		final var dollarPos = productVersion.indexOf('$');
		if (dollarPos == -1) {
			rawProduct = productVersion;
			rawVersion = null;
		}
		else {
			rawProduct = productVersion.substring(0, dollarPos);
			rawVersion = productVersion.substring(dollarPos + 1);
		}

                     this.validateRawVersion();
                     this.validateRawProduct();
	}

	final var path = uri.getRawPath();

	if (path.length() == 0) {
		rawNamespace = rawEntity = null;
		return;
	}

	int slashPos;
	if (path.charAt(0) == '/') { // We have a namespace
		slashPos = path.indexOf('/', 1); // Skip first slash

		if (slashPos == -1)  throw new IllegalArgumentException("Missing entity");
		rawNamespace = path.substring(1, slashPos);
		rawEntity = path.substring(slashPos + 1);
	}
	else {
		if (path.indexOf('/') != -1) throw new IllegalArgumentException("The entity part cannot contain a slash (namespaces must be always prefixed with a slash)"); // No slash
		rawNamespace = null;
		rawEntity = path;
	}
             this.validateRawNamespace();
             this.validateRawEntity();
}
 
Example 19
Source File: File.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a new {@code File} instance by converting the given
 * {@code file:} URI into an abstract pathname.
 *
 * <p> The exact form of a {@code file:} URI is system-dependent, hence
 * the transformation performed by this constructor is also
 * system-dependent.
 *
 * <p> For a given abstract pathname <i>f</i> it is guaranteed that
 *
 * <blockquote><code>
 * new File(</code><i>&nbsp;f</i><code>.{@link #toURI()
 * toURI}()).equals(</code><i>&nbsp;f</i><code>.{@link #getAbsoluteFile() getAbsoluteFile}())
 * </code></blockquote>
 *
 * so long as the original abstract pathname, the URI, and the new abstract
 * pathname are all created in (possibly different invocations of) the same
 * Java virtual machine.  This relationship typically does not hold,
 * however, when a {@code file:} URI that is created in a virtual machine
 * on one operating system is converted into an abstract pathname in a
 * virtual machine on a different operating system.
 *
 * @param  uri
 *         An absolute, hierarchical URI with a scheme equal to
 *         {@code "file"}, a non-empty path component, and undefined
 *         authority, query, and fragment components
 *
 * @throws  NullPointerException
 *          If {@code uri} is {@code null}
 *
 * @throws  IllegalArgumentException
 *          If the preconditions on the parameter do not hold
 *
 * @see #toURI()
 * @see java.net.URI
 * @since 1.4
 */
public File(URI uri) {

    // Check our many preconditions
    if (!uri.isAbsolute())
        throw new IllegalArgumentException("URI is not absolute");
    if (uri.isOpaque())
        throw new IllegalArgumentException("URI is not hierarchical");
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
        throw new IllegalArgumentException("URI scheme is not \"file\"");
    if (uri.getRawAuthority() != null)
        throw new IllegalArgumentException("URI has an authority component");
    if (uri.getRawFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getRawQuery() != null)
        throw new IllegalArgumentException("URI has a query component");
    String p = uri.getPath();
    if (p.equals(""))
        throw new IllegalArgumentException("URI path component is empty");

    // Okay, now initialize
    p = fs.fromURIPath(p);
    if (File.separatorChar != '/')
        p = p.replace('/', File.separatorChar);
    this.path = fs.normalize(p);
    this.prefixLength = fs.prefixLength(this.path);
}
 
Example 20
Source File: BURL.java    From BUbiNG with Apache License 2.0 2 votes vote down vote up
/** Returns the concatenated {@linkplain URI#getScheme()} and {@link URI#getRawAuthority() raw authority} of a BUbiNG URL.
 *
 * @param url a BUbiNG URL.
 * @return the concatenated {@linkplain URI#getScheme()} and {@link URI#getRawAuthority() raw authority} of <code>uri</code>.
 */
public static String schemeAndAuthority(final URI url) {
	return url.getScheme() + "://" + url.getRawAuthority();
}