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

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

源代码1 项目: openhab-core   文件: ConfigDescription.java
/**
 * Creates a new instance of this class with the specified parameters.
 *
 * @param uri the URI of this description within the {@link ConfigDescriptionRegistry}
 * @param parameters the list of configuration parameters that belong to the given URI
 * @param groups the list of groups associated with the parameters
 * @throws IllegalArgumentException if the URI is null or invalid
 * @deprecated Use the {@link ConfigDescriptionBuilder} instead.
 */
@Deprecated
ConfigDescription(URI uri, @Nullable List<ConfigDescriptionParameter> parameters,
        @Nullable List<ConfigDescriptionParameterGroup> groups) {
    if (uri == null) {
        throw new IllegalArgumentException("The URI must not be null!");
    }
    if (!uri.isAbsolute()) {
        throw new IllegalArgumentException("The scheme is missing!");
    }
    if (!uri.isOpaque()) {
        throw new IllegalArgumentException("The scheme specific part (token) must not start with a slash ('/')!");
    }

    this.uri = uri;
    this.parameters = parameters == null ? Collections.emptyList() : Collections.unmodifiableList(parameters);
    this.parameterGroups = groups == null ? Collections.emptyList() : Collections.unmodifiableList(groups);
}
 
源代码2 项目: calcite   文件: Sources.java
@Override public Source append(Source child) {
  if (isFile(child)) {
    if (child.file().isAbsolute()) {
      return child;
    }
  } else {
    try {
      URI uri = child.url().toURI();
      if (!uri.isOpaque()) {
        // The URL is "absolute" (it starts with a slash)
        return child;
      }
    } catch (URISyntaxException e) {
      throw new IllegalArgumentException("Unable to convert URL " + child.url() + " to URI", e);
    }
  }
  String path = child.path();
  if (!urlGenerated) {
    String encodedPath = new File(".").toURI().relativize(new File(path).toURI())
        .getRawSchemeSpecificPart();
    return Sources.url(url + "/" + encodedPath);
  } else {
    return Sources.file(file, path);
  }
}
 
源代码3 项目: calcite   文件: Sources.java
private static File urlToFile(URL url) {
  if (!"file".equals(url.getProtocol())) {
    return null;
  }
  URI uri;
  try {
    uri = url.toURI();
  } catch (URISyntaxException e) {
    throw new IllegalArgumentException("Unable to convert URL " + url + " to URI", e);
  }
  if (uri.isOpaque()) {
    // It is like file:test%20file.c++
    // getSchemeSpecificPart would return "test file.c++"
    return new File(uri.getSchemeSpecificPart());
  }
  // See https://stackoverflow.com/a/17870390/1261287
  return Paths.get(uri).toFile();
}
 
源代码4 项目: crate   文件: URIPattern.java
private boolean matchNormalized(URI uri) {
    if (uriPattern.isOpaque()) {
        // This url only has scheme, scheme-specific part and fragment
        return uri.isOpaque() &&
                match(uriPattern.getScheme(), uri.getScheme()) &&
                match(uriPattern.getSchemeSpecificPart(), uri.getSchemeSpecificPart()) &&
                match(uriPattern.getFragment(), uri.getFragment());

    } else {
        return match(uriPattern.getScheme(), uri.getScheme()) &&
                match(uriPattern.getAuthority(), uri.getAuthority()) &&
                match(uriPattern.getQuery(), uri.getQuery()) &&
                match(uriPattern.getPath(), uri.getPath()) &&
                match(uriPattern.getFragment(), uri.getFragment());
    }
}
 
源代码5 项目: sftp-fs   文件: SFTPFileSystemProvider.java
private void checkURI(URI uri, boolean allowUserInfo, boolean allowPath) {
    if (!uri.isAbsolute()) {
        throw Messages.uri().notAbsolute(uri);
    }
    if (!getScheme().equalsIgnoreCase(uri.getScheme())) {
        throw Messages.uri().invalidScheme(uri, getScheme());
    }
    if (!allowUserInfo && uri.getUserInfo() != null && !uri.getUserInfo().isEmpty()) {
        throw Messages.uri().hasUserInfo(uri);
    }
    if (uri.isOpaque()) {
        throw Messages.uri().notHierarchical(uri);
    }
    if (!allowPath && uri.getPath() != null && !uri.getPath().isEmpty()) {
        throw Messages.uri().hasPath(uri);
    }
    if (uri.getQuery() != null && !uri.getQuery().isEmpty()) {
        throw Messages.uri().hasQuery(uri);
    }
    if (uri.getFragment() != null && !uri.getFragment().isEmpty()) {
        throw Messages.uri().hasFragment(uri);
    }
}
 
源代码6 项目: allure-java   文件: LabelBuilder.java
private Optional<String> featurePackage(final String uriString, final String featureName) {
    final Optional<URI> maybeUri = safeUri(uriString);
    if (!maybeUri.isPresent()) {
        return Optional.empty();
    }
    URI uri = maybeUri.get();

    if (!uri.isOpaque()) {
        final URI work = new File("").toURI();
        uri = work.relativize(uri);
    }
    final String schemeSpecificPart = uri.normalize().getSchemeSpecificPart();
    final Stream<String> folders = Stream.of(schemeSpecificPart.replaceAll("\\.", "_").split("/"));
    final Stream<String> name = Stream.of(featureName);
    return Optional.of(Stream.concat(folders, name)
            .filter(Objects::nonNull)
            .filter(s -> !s.isEmpty())
            .collect(Collectors.joining(".")));
}
 
源代码7 项目: jaamsim   文件: Input.java
/**
 * Converts a file path entry in a configuration file to a URI.
 * @param kw - keyword input containing the file path data
 * @return the URI corresponding to the file path data.
 * @throws InputErrorException
 */
public static URI parseURI(KeywordIndex kw)
throws InputErrorException {
	Input.assertCount(kw, 1);

	String arg = kw.getArg(0);

	// Convert the file path to a URI
	URI uri = null;
	try {
		if (kw.context != null)
			uri = InputAgent.getFileURI(kw.context.context, arg, kw.context.jail);
		else
			uri = InputAgent.getFileURI(null, arg, null);
	}
	catch (URISyntaxException ex) {
		throw new InputErrorException("File Entity parse error: %s", ex.getMessage());
	}

	if (uri == null)
		throw new InputErrorException("Unable to parse the file path:\n%s", arg);

	if (!uri.isOpaque() && uri.getPath() == null)
		 throw new InputErrorException("Unable to parse the file path:\n%s", arg);

	return uri;
}
 
源代码8 项目: caja   文件: DataUriFetcher.java
private static boolean isDataUri(URI uri) {
  if (null != uri  && "data".equals(uri.getScheme())
      && uri.isOpaque()) {
    return true;
  }
  return false;
}
 
源代码9 项目: smarthome   文件: ConfigDescription.java
/**
 * Creates a new instance of this class with the specified parameters.
 *
 * @param uri the URI of this description within the {@link ConfigDescriptionRegistry} (must neither be null nor
 *            empty)
 * @param parameters the list of configuration parameters that belong to the given URI
 *            (could be null or empty)
 * @param groups the list of groups associated with the parameters
 * @throws IllegalArgumentException if the URI is null or invalid
 */
public ConfigDescription(URI uri, List<ConfigDescriptionParameter> parameters,
        List<ConfigDescriptionParameterGroup> groups) {
    if (uri == null) {
        throw new IllegalArgumentException("The URI must not be null!");
    }
    if (!uri.isAbsolute()) {
        throw new IllegalArgumentException("The scheme is missing!");
    }
    if (!uri.isOpaque()) {
        throw new IllegalArgumentException("The scheme specific part (token) must not start with a slash ('/')!");
    }

    this.uri = uri;

    if (parameters != null) {
        this.parameters = Collections.unmodifiableList(parameters);
    } else {
        this.parameters = Collections.unmodifiableList(new ArrayList<ConfigDescriptionParameter>(0));
    }

    if (groups != null) {
        this.parameterGroups = Collections.unmodifiableList(groups);
    } else {
        this.parameterGroups = Collections.unmodifiableList(new ArrayList<ConfigDescriptionParameterGroup>(0));
    }
}
 
源代码10 项目: openjdk-8-source   文件: 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.getFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getQuery() != 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.getAuthority();
    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);
}
 
源代码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 项目: tuxguitar   文件: TGFileUtils.java
public static String getDecodedFileName(URI uri) {
	return (!uri.isOpaque() ? getDecodedFileName(uri.getPath()) : null);
}
 
源代码13 项目: TencentKona-8   文件: 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.getFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getQuery() != 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.getAuthority();
    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);
}
 
源代码14 项目: 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;
}
 
源代码15 项目: jdk8u_jdk   文件: File.java
/**
 * Creates a new <tt>File</tt> instance by converting the given
 * <tt>file:</tt> URI into an abstract pathname.
 *
 * <p> The exact form of a <tt>file:</tt> 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><tt>
 * new File(</tt><i>&nbsp;f</i><tt>.{@link #toURI() toURI}()).equals(</tt><i>&nbsp;f</i><tt>.{@link #getAbsoluteFile() getAbsoluteFile}())
 * </tt></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 <tt>file:</tt> 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
 *         <tt>"file"</tt>, a non-empty path component, and undefined
 *         authority, query, and fragment components
 *
 * @throws  NullPointerException
 *          If <tt>uri</tt> is <tt>null</tt>
 *
 * @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.getAuthority() != null)
        throw new IllegalArgumentException("URI has an authority component");
    if (uri.getFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getQuery() != 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);
}
 
源代码16 项目: jdk-1.7-annotated   文件: File.java
/**
 * Creates a new <tt>File</tt> instance by converting the given
 * <tt>file:</tt> URI into an abstract pathname.
 *
 * <p> The exact form of a <tt>file:</tt> 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><tt>
 * new File(</tt><i>&nbsp;f</i><tt>.{@link #toURI() toURI}()).equals(</tt><i>&nbsp;f</i><tt>.{@link #getAbsoluteFile() getAbsoluteFile}())
 * </tt></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 <tt>file:</tt> 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
 *         <tt>"file"</tt>, a non-empty path component, and undefined
 *         authority, query, and fragment components
 *
 * @throws  NullPointerException
 *          If <tt>uri</tt> is <tt>null</tt>
 *
 * @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.getAuthority() != null)
        throw new IllegalArgumentException("URI has an authority component");
    if (uri.getFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getQuery() != 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);
}
 
源代码17 项目: jdk8u-dev-jdk   文件: File.java
/**
 * Creates a new <tt>File</tt> instance by converting the given
 * <tt>file:</tt> URI into an abstract pathname.
 *
 * <p> The exact form of a <tt>file:</tt> 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><tt>
 * new File(</tt><i>&nbsp;f</i><tt>.{@link #toURI() toURI}()).equals(</tt><i>&nbsp;f</i><tt>.{@link #getAbsoluteFile() getAbsoluteFile}())
 * </tt></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 <tt>file:</tt> 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
 *         <tt>"file"</tt>, a non-empty path component, and undefined
 *         authority, query, and fragment components
 *
 * @throws  NullPointerException
 *          If <tt>uri</tt> is <tt>null</tt>
 *
 * @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.getAuthority() != null)
        throw new IllegalArgumentException("URI has an authority component");
    if (uri.getFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getQuery() != 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);
}
 
源代码18 项目: openjdk-jdk8u-backup   文件: File.java
/**
 * Creates a new <tt>File</tt> instance by converting the given
 * <tt>file:</tt> URI into an abstract pathname.
 *
 * <p> The exact form of a <tt>file:</tt> 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><tt>
 * new File(</tt><i>&nbsp;f</i><tt>.{@link #toURI() toURI}()).equals(</tt><i>&nbsp;f</i><tt>.{@link #getAbsoluteFile() getAbsoluteFile}())
 * </tt></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 <tt>file:</tt> 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
 *         <tt>"file"</tt>, a non-empty path component, and undefined
 *         authority, query, and fragment components
 *
 * @throws  NullPointerException
 *          If <tt>uri</tt> is <tt>null</tt>
 *
 * @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.getAuthority() != null)
        throw new IllegalArgumentException("URI has an authority component");
    if (uri.getFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getQuery() != 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);
}
 
源代码19 项目: jdk8u-jdk   文件: File.java
/**
 * Creates a new <tt>File</tt> instance by converting the given
 * <tt>file:</tt> URI into an abstract pathname.
 *
 * <p> The exact form of a <tt>file:</tt> 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><tt>
 * new File(</tt><i>&nbsp;f</i><tt>.{@link #toURI() toURI}()).equals(</tt><i>&nbsp;f</i><tt>.{@link #getAbsoluteFile() getAbsoluteFile}())
 * </tt></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 <tt>file:</tt> 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
 *         <tt>"file"</tt>, a non-empty path component, and undefined
 *         authority, query, and fragment components
 *
 * @throws  NullPointerException
 *          If <tt>uri</tt> is <tt>null</tt>
 *
 * @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.getAuthority() != null)
        throw new IllegalArgumentException("URI has an authority component");
    if (uri.getFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getQuery() != 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 项目: Java8CN   文件: File.java
/**
 * Creates a new <tt>File</tt> instance by converting the given
 * <tt>file:</tt> URI into an abstract pathname.
 *
 * <p> The exact form of a <tt>file:</tt> 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><tt>
 * new File(</tt><i>&nbsp;f</i><tt>.{@link #toURI() toURI}()).equals(</tt><i>&nbsp;f</i><tt>.{@link #getAbsoluteFile() getAbsoluteFile}())
 * </tt></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 <tt>file:</tt> 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
 *         <tt>"file"</tt>, a non-empty path component, and undefined
 *         authority, query, and fragment components
 *
 * @throws  NullPointerException
 *          If <tt>uri</tt> is <tt>null</tt>
 *
 * @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.getAuthority() != null)
        throw new IllegalArgumentException("URI has an authority component");
    if (uri.getFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getQuery() != 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);
}