--- old/src/java.base/share/classes/java/nio/file/Paths.java 2018-09-10 14:12:18.839490752 -0400 +++ new/src/java.base/share/classes/java/nio/file/Paths.java 2018-09-10 14:12:18.375490752 -0400 @@ -25,13 +25,22 @@ package java.nio.file; -import java.nio.file.spi.FileSystemProvider; +import jdk.internal.util.PathParser; + +import java.io.File; import java.net.URI; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; /** * This class consists exclusively of static methods that return a {@link Path} * by converting a path string or {@link URI}. * + *

Unless otherwise noted, passing a {@code null} argument to a method + * in this class will cause a {@link NullPointerException} to be thrown. + * * @apiNote * It is recommended to obtain a {@code Path} via the {@code Path.of} methods * instead of via the {@code get} methods defined in this class as this class @@ -96,4 +105,55 @@ public static Path get(URI uri) { return Path.of(uri); } + + /** + * Returns a list of path strings parsed from a string with empty paths removed. + * The {@link File#pathSeparator} is used to split the string and + * empty strings are removed. A list is created of the remaining strings. + *

+ * The {@code pathSeparator} character can be included in a path + * on operating systems that support quoting segments of the string. + * + * @implNote On Windows, quoting of path segments is supported. + * Each {@link File#pathSeparator} between pairs of quotation marks (@code 'U+0022') + * is considered an ordinary character and the quotes are omitted from the path. + * An unmatched double-quote is matched by the end of the string. + * + * @param path a {@code non-null} string containing paths separated by + * {@link File#pathSeparator}. + * @return a {@code non-null} immutable list of strings for each non-empty path + */ + public static List pathToStrings(String path) { + Objects.requireNonNull(path, "path"); + return List.of(PathParser.parsePath(path, null)); + } + + /** + * Returns a list of Paths parsed from a string with empty paths removed. + * The {@link File#pathSeparator} is used to split the string and + * empty strings are removed. A list is created of the remaining strings after + * mapping each string using {@link Path#of Path.of} using the + * {@link FileSystems#getDefault default} {@link FileSystem}. + *

+ * The {@code pathSeparator} character can be included in a path + * on operating systems that support quoting segments of the string. + * + * @implNote On Windows, quoting of path segments is supported. + * Each {@link File#pathSeparator} between pairs of quotation marks (@code 'U+0022') + * is considered an ordinary character and the quotes are omitted from the path. + * An unmatched double-quote is matched by the end of the string. + * + * @param path a {@code non-null} string containing paths separated by + * {@link File#pathSeparator}. + * @return a {@code non-null} immutable list of Paths for each non-empty path + * + * @throws InvalidPathException + * if each path string cannot be converted to a {@code Path} + */ + public static List pathToPaths(String path) { + Objects.requireNonNull(path, "path"); + return Arrays.stream(PathParser.parsePath(path, null)) + .map(s -> Path.of(s)) + .collect(Collectors.toList()); + } }