Interface ResourceId
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
ClassLoaderFileSystem.ClassLoaderResourceId
,GcsResourceId
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 ofString
resource names or globs, queries theFileSystem
for resources matching these specifications, and returns aMatchResult
for each glob. This is typically used when reading from files.FileSystems.matchNewResource(String, boolean)
, which takes aString
full resource name and type (file or directory) and generates aFileSystem
-specificResourceId
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 generateResourceIds
for resources that may not yet exist.
-
Method Summary
Modifier and TypeMethodDescriptionReturns theResourceId
that represents the current directory of thisResourceId
.Returns the name of the file or directory denoted by thisResourceId
.Get the scheme which defines the namespace of theResourceId
.boolean
Returnstrue
if thisResourceId
represents a directory, false otherwise.resolve
(String other, ResolveOptions resolveOptions) Returns a childResourceId
underthis
.toString()
Returns the string representation of thisResourceId
.
-
Method Details
-
resolve
Returns a childResourceId
underthis
.In order to write file system agnostic code, callers should not include delimiters in
other
, and should useResolveOptions.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 thisResourceId
.resourceId.resolve("*", StandardResolveOptions.RESOLVE_FILE)
returns aResourceId
which matches all files in thisResourceId
.resourceId.resolve("*", StandardResolveOptions.RESOLVE_DIRECTORY)
returns aResourceId
which matches all directories in thisResourceId
.
- Throws:
IllegalStateException
- if thisResourceId
is not a directory.IllegalArgumentException
- ifother
contains illegal characters or is an illegal name. It is recommended that callers use common characters, such as[_a-zA-Z0-9.-]
, inother
.
-
getCurrentDirectory
ResourceId getCurrentDirectory()Returns theResourceId
that represents the current directory of thisResourceId
.If it is already a directory, trivially returns this.
-
getScheme
String getScheme()Get the scheme which defines the namespace of theResourceId
.The scheme is required to follow URI scheme syntax. See RFC 2396
-
getFilename
Returns the name of the file or directory denoted by thisResourceId
. The file name is the farthest element from the root in the directory hierarchy.- Returns:
- a string representing the name of file or directory, or null if there are zero components.
-
isDirectory
boolean isDirectory()Returnstrue
if thisResourceId
represents a directory, false otherwise. -
toString
String toString()Returns the string representation of thisResourceId
.The corresponding
FileSystem.match(java.util.List<java.lang.String>)
is required to accept this string representation.
-