@Experimental(value=FILESYSTEM) public interface ResourceId extends java.io.Serializable
ResourceId is hierarchical and composed of a sequence of directory
and file name elements separated by a special separator or delimiter.
ResourceIds are created using FileSystems. The two primary
mechanisms are:
FileSystems.match(java.util.List), which takes a list of String resource
names or globs, queries the FileSystem for resources matching these specifications,
and returns a MatchResult for each glob. This is typically used when reading from
files.
FileSystems.matchNewResource(String, boolean), which takes a String full
resource name and type (file or directory) and generates a FileSystem-specific
ResourceId for that resource. This call does not verify the presence or absence of that
resource in the file system. This call is typically used when creating new directories or files
to generate ResourceIds for resources that may not yet exist.
| Modifier and Type | Method and Description |
|---|---|
ResourceId |
getCurrentDirectory()
Returns the
ResourceId that represents the current directory of
this ResourceId. |
java.lang.String |
getFilename()
Returns the name of the file or directory denoted by this
ResourceId. |
java.lang.String |
getScheme()
Get the scheme which defines the namespace of the
ResourceId. |
boolean |
isDirectory()
Returns
true if this ResourceId represents a directory, false otherwise. |
ResourceId |
resolve(java.lang.String other,
ResolveOptions resolveOptions)
Returns a child
ResourceId under this. |
java.lang.String |
toString()
Returns the string representation of this
ResourceId. |
ResourceId resolve(java.lang.String other, ResolveOptions resolveOptions)
ResourceId under this.
In order to write file system agnostic code, callers should not include delimiters
in other, and should use ResolveOptions.StandardResolveOptions to specify
whether to resolve a file or a directory.
For example:
ResourceId homeDir = ...;
ResourceId tempOutput = homeDir
.resolve("tempDir", StandardResolveOptions.RESOLVE_DIRECTORY)
.resolve("output", StandardResolveOptions.RESOLVE_FILE);
This ResourceId should represents a directory.
It is up to each file system to resolve in their own way.
Resolving special characters:
resourceId.resolve("..", StandardResolveOptions.RESOLVE_DIRECTORY) returns
the parent directory of this ResourceId.
resourceId.resolve("{@literal *}", StandardResolveOptions.RESOLVE_FILE) returns
a ResourceId which matches all files in this ResourceId.
resourceId.resolve("{@literal *}", StandardResolveOptions.RESOLVE_DIRECTORY)
returns a ResourceId which matches all directories in this ResourceId.
java.lang.IllegalStateException - if this ResourceId is not a directory.java.lang.IllegalArgumentException - if other contains illegal characters
or is an illegal name. It is recommended that callers use common characters,
such as [_a-zA-Z0-9.-], in other.ResourceId getCurrentDirectory()
ResourceId that represents the current directory of
this ResourceId.
If it is already a directory, trivially returns this.
java.lang.String getScheme()
ResourceId.
The scheme is required to follow URI scheme syntax. See RFC 2396
@Nullable java.lang.String getFilename()
ResourceId. The file name
is the farthest element from the root in the directory hierarchy.boolean isDirectory()
true if this ResourceId represents a directory, false otherwise.java.lang.String toString()
ResourceId.
The corresponding FileSystem.match(java.util.List<java.lang.String>) is required to accept this string representation.
toString in class java.lang.Object