Class GcsPath
- All Implemented Interfaces:
Serializable
,Comparable<Path>
,Iterable<Path>
,Path
,Watchable
Path
API for Google Cloud Storage paths.
GcsPath uses a slash ('/') as a directory separator. Below is a summary of how slashes are treated:
- A GCS bucket may not contain a slash. An object may contain zero or more slashes.
- A trailing slash always indicates a directory, which is compliant with POSIX.1-2008.
- Slashes separate components of a path. Empty components are allowed, these are represented as repeated slashes. An empty component always refers to a directory, and always ends in a slash.
getParent()
} always returns a path ending in a slash, as the parent of a GcsPath is always a directory.- Use
resolve(String)
to append elements to a GcsPath -- this applies the rules consistently and is highly recommended over any custom string concatenation.
GcsPath treats all GCS objects and buckets as belonging to the same filesystem, so the root of a GcsPath is the GcsPath bucket="", object="".
Relative paths are not associated with any bucket. This matches common treatment of Path in which relative paths can be constructed from one filesystem and appended to another filesystem.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
boolean
boolean
boolean
static GcsPath
fromComponents
(@Nullable String bucket, @Nullable String object) Creates a GcsPath from bucket and object components.static GcsPath
fromObject
(StorageObject object) Creates a GcsPath from a StorageObject.static GcsPath
fromResourceName
(String name) Creates a GcsPath from a OnePlatform resource name in string form.static GcsPath
Creates a GcsPath from a URI in string form.static GcsPath
Creates a GcsPath from a URI.Returns the bucket name associated with this GCS path, or an empty string if this is a relative path component.getName
(int count) int
Returns the object name associated with this GCS path, or an empty string if no object is specified.Returns the parent path, ornull
if this path does not have a parent.getRoot()
int
hashCode()
boolean
iterator()
register
(WatchService watcher, WatchEvent.Kind<?>... events) register
(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) relativize
(Path other) resolveSibling
(String other) resolveSibling
(Path other) void
boolean
startsWith
(String prefix) boolean
startsWith
(Path other) subpath
(int beginIndex, int endIndex) toFile()
toRealPath
(LinkOption... options) toString()
toUri()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
SCHEME
- See Also:
-
GCS_URI
Pattern that is used to parse a GCS URL.This is used to separate the components. Verification is handled separately.
-
-
Constructor Details
-
GcsPath
Constructs a GcsPath.- Parameters:
fs
- the associated FileSystem, if anybucket
- the associated bucket, or none (null
or an empty string) for a relative path componentobject
- the object, which is a fully-qualified object name if bucket was also provided, or none (null
or an empty string) for no object- Throws:
IllegalArgumentException
- if the bucket of object names are invalid.
-
-
Method Details
-
fromUri
Creates a GcsPath from a URI.The URI must be in the form
gs://[bucket]/[path]
, and may not contain a port, user info, a query, or a fragment. -
fromUri
Creates a GcsPath from a URI in string form.This does not use URI parsing, which means it may accept patterns that the URI parser would not accept.
-
fromResourceName
Creates a GcsPath from a OnePlatform resource name in string form. -
fromObject
Creates a GcsPath from a StorageObject. -
fromComponents
Creates a GcsPath from bucket and object components.A GcsPath without a bucket name is treated as a relative path, which is a path component with no linkage to the root element. This is similar to a Unix path that does not begin with the root marker (a slash). GCS has different naming constraints and APIs for working with buckets and objects, so these two concepts are kept separate to avoid accidental attempts to treat objects as buckets, or vice versa, as much as possible.
A GcsPath without an object name is a bucket reference. A bucket is always a directory, which could be used to lookup or add files to a bucket, but could not be opened as a file.
A GcsPath containing neither bucket or object names is treated as the root of the GCS filesystem. A listing on the root element would return the buckets available to the user.
If
null
is passed as either parameter, it is converted to an empty string internally for consistency. There is no distinction between an empty string and anull
, as neither are allowed by GCS.- Parameters:
bucket
- a GCS bucket name, or none (null
or an empty string) if the object is not associated with a bucket (e.g. relative paths or the root node).object
- a GCS object path, or none (null
or an empty string) for no object.
-
getBucket
Returns the bucket name associated with this GCS path, or an empty string if this is a relative path component. -
getObject
Returns the object name associated with this GCS path, or an empty string if no object is specified. -
setFileSystem
-
getFileSystem
- Specified by:
getFileSystem
in interfacePath
-
isAbsolute
public boolean isAbsolute()- Specified by:
isAbsolute
in interfacePath
-
getRoot
-
getFileName
- Specified by:
getFileName
in interfacePath
-
getParent
Returns the parent path, ornull
if this path does not have a parent.Returns a path that ends in '/', as the parent path always refers to a directory.
-
getNameCount
public int getNameCount()- Specified by:
getNameCount
in interfacePath
-
getName
-
subpath
-
startsWith
- Specified by:
startsWith
in interfacePath
-
startsWith
- Specified by:
startsWith
in interfacePath
-
endsWith
-
endsWith
-
normalize
-
resolve
-
resolve
-
resolveSibling
- Specified by:
resolveSibling
in interfacePath
-
resolveSibling
- Specified by:
resolveSibling
in interfacePath
-
relativize
- Specified by:
relativize
in interfacePath
-
toAbsolutePath
- Specified by:
toAbsolutePath
in interfacePath
-
toRealPath
- Specified by:
toRealPath
in interfacePath
- Throws:
IOException
-
toFile
-
register
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException - Specified by:
register
in interfacePath
- Specified by:
register
in interfaceWatchable
- Throws:
IOException
-
register
- Specified by:
register
in interfacePath
- Specified by:
register
in interfaceWatchable
- Throws:
IOException
-
iterator
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Path>
- Specified by:
compareTo
in interfacePath
-
equals
-
hashCode
public int hashCode() -
toString
-
toResourceName
-
toUri
-