Class PathType
java.lang.Object
com.google.common.jimfs.PathType
- Direct Known Subclasses:
UnixPathType, WindowsPathType
An object defining a specific type of path. Knows how to parse strings to a path and how to
render a path as a string as well as what the path separator is and what other separators are
recognized when parsing paths.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classSimple result of parsing a path. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPathType(boolean allowsMultipleRoots, char separator, char... otherSeparators) -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanReturns whether or not this type of path allows multiple root directories.private static voidappendToRegex(char separator, StringBuilder patternBuilder) private static com.google.common.base.SplittercreateSplitter(char separator, char... otherSeparators) protected final PathType.ParseResultReturns an empty path.final PathType.ParseResultParses a path from the given URI.final StringReturns the other separators that are recognized when parsing a path.final StringReturns the canonical separator for this path type.private static booleanisRegexReserved(char c) final com.google.common.base.Joinerjoiner()Returns the path joiner for this path type.abstract PathType.ParseResultParses the given strings as a path.protected abstract PathType.ParseResultparseUriPath(String uriPath) Parses a path from the given URI path.final com.google.common.base.Splittersplitter()Returns the path splitter for this path type.toString()abstract StringReturns the string form of the given path.final URICreates a URI for the path with the given root and names in the file system with the given URI.protected abstract StringReturns the string form of the given path for use in the path part of a URI.static PathTypeunix()Returns a Unix-style path type.static PathTypewindows()Returns a Windows-style path type.
-
Field Details
-
allowsMultipleRoots
private final boolean allowsMultipleRoots -
separator
-
otherSeparators
-
joiner
private final com.google.common.base.Joiner joiner -
splitter
private final com.google.common.base.Splitter splitter -
regexReservedChars
private static final char[] regexReservedChars
-
-
Constructor Details
-
PathType
protected PathType(boolean allowsMultipleRoots, char separator, char... otherSeparators)
-
-
Method Details
-
unix
Returns a Unix-style path type. "/" is both the root and the only separator. Any path starting with "/" is considered absolute. The nul character ('\0') is disallowed in paths. -
windows
Returns a Windows-style path type. The canonical separator character is "\". "/" is also treated as a separator when parsing paths.As much as possible, this implementation follows the information provided in this article. Paths with drive-letter roots (e.g. "C:\") and paths with UNC roots (e.g. "\\host\share\") are supported.
Two Windows path features are not currently supported as they are too Windows-specific:
- Relative paths containing a drive-letter root, for example "C:" or "C:foo\bar". Such paths have a root component and optionally have names, but are relative paths, relative to the working directory of the drive identified by the root.
- Absolute paths with no root, for example "\foo\bar". Such paths are absolute paths on the current drive.
-
isRegexReserved
private static boolean isRegexReserved(char c) -
createSplitter
private static com.google.common.base.Splitter createSplitter(char separator, char... otherSeparators) -
appendToRegex
-
allowsMultipleRoots
public final boolean allowsMultipleRoots()Returns whether or not this type of path allows multiple root directories. -
getSeparator
Returns the canonical separator for this path type. The returned string always has a length of one. -
getOtherSeparators
Returns the other separators that are recognized when parsing a path. If no other separators are recognized, the empty string is returned. -
joiner
public final com.google.common.base.Joiner joiner()Returns the path joiner for this path type. -
splitter
public final com.google.common.base.Splitter splitter()Returns the path splitter for this path type. -
emptyPath
Returns an empty path. -
parsePath
Parses the given strings as a path.- Throws:
InvalidPathException- if the path isn't valid for this path type
-
toString
-
toString
-
toUriPath
Returns the string form of the given path for use in the path part of a URI. The root element is not nullable as the path must be absolute. The elements of the returned path do not need to be escaped. Thedirectoryboolean indicates whether the file the URI is for is known to be a directory. -
parseUriPath
Parses a path from the given URI path.- Throws:
InvalidPathException- if the given path isn't valid for this path type
-
toUri
-
fromUri
Parses a path from the given URI.
-