< prev index next >
src/java.base/share/classes/java/nio/file/Paths.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -31,10 +31,11 @@
/**
* This class consists exclusively of static methods that return a {@link Path}
* by converting a path string or {@link URI}.
*
* @since 1.7
+ * @see Path
*/
public final class Paths {
private Paths() { }
@@ -66,10 +67,14 @@
* <pre>
* Path dir = ...
* Path path = dir.resolve("file");
* </pre>
*
+ * @implSpec
+ * This method simply invokes {@link Path#get(String,String...)
+ * Path.get(String, String...)} with the given parameters.
+ *
* @param first
* the path string or initial part of the path string
* @param more
* additional strings to be joined to form the path string
*
@@ -77,13 +82,14 @@
*
* @throws InvalidPathException
* if the path string cannot be converted to a {@code Path}
*
* @see FileSystem#getPath
+ * @see Path#get(String,String...)
*/
public static Path get(String first, String... more) {
- return FileSystems.getDefault().getPath(first, more);
+ return Path.get(first, more);
}
/**
* Converts the given URI to a {@link Path} object.
*
@@ -110,10 +116,14 @@
* so long as the original {@code Path}, the {@code URI}, and the new {@code
* Path} are all created in (possibly different invocations of) the same
* Java virtual machine. Whether other providers make any guarantees is
* provider specific and therefore unspecified.
*
+ * @implSpec
+ * <p> This method simply invokes {@link Path#get(URI)
+ * Path.get(URI)} with the given parameter.
+ *
* @param uri
* the URI to convert
*
* @return the resulting {@code Path}
*
@@ -125,25 +135,12 @@
* cannot be created automatically, or the provider identified by
* the URI's scheme component is not installed
* @throws SecurityException
* if a security manager is installed and it denies an unspecified
* permission to access the file system
+ *
+ * @see Path#get(URI)
*/
public static Path get(URI uri) {
- String scheme = uri.getScheme();
- if (scheme == null)
- throw new IllegalArgumentException("Missing scheme");
-
- // check for default provider to avoid loading of installed providers
- if (scheme.equalsIgnoreCase("file"))
- return FileSystems.getDefault().provider().getPath(uri);
-
- // try to find provider
- for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
- if (provider.getScheme().equalsIgnoreCase(scheme)) {
- return provider.getPath(uri);
- }
- }
-
- throw new FileSystemNotFoundException("Provider \"" + scheme + "\" not installed");
+ return Path.get(uri);
}
}
< prev index next >