API for parsing path strings
Roger Riggs
Roger.Riggs at Oracle.com
Thu Jul 19 19:39:14 UTC 2018
Hi,
Parsing of paths such as the values of properties java.class.path and
java.library.path
do not have direct support in the Java API.
There are several implementations within OpenJDK and a few variations
exist with regard to
treatment of empty path elements and on Windows support for quoting.
Would it be useful to have an API such as the following:
/**
* Returns a list of paths parsed from a string separated by {@link File#pathSeparator}.
* All characters except the {@link File#pathSeparator} are allowed.
* Some operating systems support quoting segments of the string
* potentially including {@code pathSeparator} characters.
* Empty paths, identified by leading, trailing, and adjacent separator characters,
* can be omitted or replaced with a non-null provided path.
*
* @implNote
* On Windows, zero or more characters between double-quotes ({@code "}) are included
* literally in the path, regardless of whether they are valid in a path.
*
* @param path a string containing paths separated by the {@link File#pathSeparator}
* @param emptyPath a path to replace an empty path or {@code null} to ignore empty paths
* @return an immutable list of strings for each path; {@code non-null}
*/
public static List<String> parsePathStrings(String path, String emptyPath) { ...}
There are of course, possible variations and convenience versions but
the API should be kept to the essentials.
With java.util.streams it becomes easy to process each component or to
map the strings to Files or Path.
Suggestions welcome, Roger
More information about the core-libs-dev
mailing list