java.net.URI#getRawAuthority ( )源码实例Demo

下面列出了java.net.URI#getRawAuthority ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: es6draft   文件: SourceIdentifiers.java
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;
}
 
源代码2 项目: armeria   文件: ArmeriaClientHttpConnector.java
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);
}
 
源代码3 项目: nano-framework   文件: URIBuilder.java
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;
}
 
源代码4 项目: CloverETL-Engine   文件: SMBOperationHandler.java
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();
}
 
源代码5 项目: RoboZombie   文件: URIBuilder.java
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();
}
 
源代码6 项目: openjdk-jdk9   文件: UnixFileSystemProvider.java
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");
}
 
源代码7 项目: BUbiNG   文件: ParsingThread.java
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;
}
 
源代码8 项目: BigApp_Discuz_Android   文件: URIBuilder.java
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();
}
 
源代码9 项目: fasten   文件: FastenURI.java
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();
}
 
源代码10 项目: r2dbc-spi   文件: ConnectionUrlParser.java
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();
    }
 
源代码11 项目: openjdk-jdk9   文件: WindowsUriSupport.java
/**
 * 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);
}
 
源代码12 项目: hadoop   文件: AzureNativeFileSystemStore.java
/**
 * 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];
}
 
源代码13 项目: hadoop   文件: AzureNativeFileSystemStore.java
/**
 * 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];
}
 
源代码14 项目: big-c   文件: AzureNativeFileSystemStore.java
/**
 * 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];
}
 
源代码15 项目: big-c   文件: AzureNativeFileSystemStore.java
/**
 * 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];
}
 
源代码16 项目: emodb   文件: EmoUriBuilder.java
@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;
}
 
源代码17 项目: armeria   文件: ClientFactory.java
/**
 * 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);
    }
}
 
源代码18 项目: timbuctoo   文件: HttpRequest.java
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;
}
 
源代码19 项目: openjdk-jdk9   文件: File.java
/**
 * 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);
}
 
源代码20 项目: BUbiNG   文件: BURL.java
/** 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();
}