public class GcsPath
extends java.lang.Object
implements java.nio.file.Path, java.io.Serializable
Path
API for Google Cloud Storage paths.
GcsPath uses a slash ('/') as a directory separator. Below is a summary of how slashes are treated:
getParent()
} always returns a path ending in a slash, as the parent of a GcsPath
is always a directory.
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.
Modifier and Type | Field and Description |
---|---|
static java.util.regex.Pattern |
GCS_URI
Pattern that is used to parse a GCS URL.
|
static java.lang.String |
SCHEME |
Constructor and Description |
---|
GcsPath(@Nullable java.nio.file.FileSystem fs,
@Nullable java.lang.String bucket,
@Nullable java.lang.String object)
Constructs a GcsPath.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(java.nio.file.Path other) |
boolean |
endsWith(java.nio.file.Path other) |
boolean |
endsWith(java.lang.String suffix) |
boolean |
equals(@Nullable java.lang.Object o) |
static GcsPath |
fromComponents(@Nullable java.lang.String bucket,
@Nullable java.lang.String object)
Creates a GcsPath from bucket and object components.
|
static GcsPath |
fromObject(StorageObject object)
Creates a GcsPath from a StorageObject.
|
static GcsPath |
fromResourceName(java.lang.String name)
Creates a GcsPath from a OnePlatform resource name in string form.
|
static GcsPath |
fromUri(java.lang.String uri)
Creates a GcsPath from a URI in string form.
|
static GcsPath |
fromUri(java.net.URI uri)
Creates a GcsPath from a URI.
|
java.lang.String |
getBucket()
Returns the bucket name associated with this GCS path, or an empty string if this is a relative
path component.
|
GcsPath |
getFileName() |
java.nio.file.FileSystem |
getFileSystem() |
GcsPath |
getName(int count) |
int |
getNameCount() |
java.lang.String |
getObject()
Returns the object name associated with this GCS path, or an empty string if no object is
specified.
|
GcsPath |
getParent()
Returns the parent path, or
null if this path does not have a parent. |
GcsPath |
getRoot() |
int |
hashCode() |
boolean |
isAbsolute() |
java.util.Iterator<java.nio.file.Path> |
iterator() |
GcsPath |
normalize() |
java.nio.file.WatchKey |
register(java.nio.file.WatchService watcher,
java.nio.file.WatchEvent.Kind<?>... events) |
java.nio.file.WatchKey |
register(java.nio.file.WatchService watcher,
java.nio.file.WatchEvent.Kind<?>[] events,
java.nio.file.WatchEvent.Modifier... modifiers) |
java.nio.file.Path |
relativize(java.nio.file.Path other) |
GcsPath |
resolve(java.nio.file.Path other) |
GcsPath |
resolve(java.lang.String other) |
java.nio.file.Path |
resolveSibling(java.nio.file.Path other) |
java.nio.file.Path |
resolveSibling(java.lang.String other) |
void |
setFileSystem(java.nio.file.FileSystem fs) |
boolean |
startsWith(java.nio.file.Path other) |
boolean |
startsWith(java.lang.String prefix) |
GcsPath |
subpath(int beginIndex,
int endIndex) |
GcsPath |
toAbsolutePath() |
java.io.File |
toFile() |
GcsPath |
toRealPath(java.nio.file.LinkOption... options) |
java.lang.String |
toResourceName() |
java.lang.String |
toString() |
java.net.URI |
toUri() |
public static final java.lang.String SCHEME
public static final java.util.regex.Pattern GCS_URI
This is used to separate the components. Verification is handled separately.
public GcsPath(@Nullable java.nio.file.FileSystem fs, @Nullable java.lang.String bucket, @Nullable java.lang.String object)
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 objectjava.lang.IllegalArgumentException
- if the bucket of object names are invalid.public static GcsPath fromUri(java.net.URI uri)
The URI must be in the form gs://[bucket]/[path]
, and may not contain a port, user
info, a query, or a fragment.
public static GcsPath fromUri(java.lang.String uri)
This does not use URI parsing, which means it may accept patterns that the URI parser would not accept.
public static GcsPath fromResourceName(java.lang.String name)
public static GcsPath fromObject(StorageObject object)
public static GcsPath fromComponents(@Nullable java.lang.String bucket, @Nullable java.lang.String object)
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 a null
, as neither
are allowed by GCS.
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.public java.lang.String getBucket()
public java.lang.String getObject()
public void setFileSystem(java.nio.file.FileSystem fs)
public java.nio.file.FileSystem getFileSystem()
getFileSystem
in interface java.nio.file.Path
public boolean isAbsolute()
isAbsolute
in interface java.nio.file.Path
public GcsPath getRoot()
getRoot
in interface java.nio.file.Path
public GcsPath getFileName()
getFileName
in interface java.nio.file.Path
public GcsPath getParent()
null
if this path does not have a parent.
Returns a path that ends in '/', as the parent path always refers to a directory.
getParent
in interface java.nio.file.Path
public int getNameCount()
getNameCount
in interface java.nio.file.Path
public GcsPath getName(int count)
getName
in interface java.nio.file.Path
public GcsPath subpath(int beginIndex, int endIndex)
subpath
in interface java.nio.file.Path
public boolean startsWith(java.nio.file.Path other)
startsWith
in interface java.nio.file.Path
public boolean startsWith(java.lang.String prefix)
startsWith
in interface java.nio.file.Path
public boolean endsWith(java.nio.file.Path other)
endsWith
in interface java.nio.file.Path
public boolean endsWith(java.lang.String suffix)
endsWith
in interface java.nio.file.Path
public GcsPath normalize()
normalize
in interface java.nio.file.Path
public GcsPath resolve(java.nio.file.Path other)
resolve
in interface java.nio.file.Path
public GcsPath resolve(java.lang.String other)
resolve
in interface java.nio.file.Path
public java.nio.file.Path resolveSibling(java.nio.file.Path other)
resolveSibling
in interface java.nio.file.Path
public java.nio.file.Path resolveSibling(java.lang.String other)
resolveSibling
in interface java.nio.file.Path
public java.nio.file.Path relativize(java.nio.file.Path other)
relativize
in interface java.nio.file.Path
public GcsPath toAbsolutePath()
toAbsolutePath
in interface java.nio.file.Path
public GcsPath toRealPath(java.nio.file.LinkOption... options) throws java.io.IOException
toRealPath
in interface java.nio.file.Path
java.io.IOException
public java.io.File toFile()
toFile
in interface java.nio.file.Path
public java.nio.file.WatchKey register(java.nio.file.WatchService watcher, java.nio.file.WatchEvent.Kind<?>[] events, java.nio.file.WatchEvent.Modifier... modifiers) throws java.io.IOException
register
in interface java.nio.file.Path
register
in interface java.nio.file.Watchable
java.io.IOException
public java.nio.file.WatchKey register(java.nio.file.WatchService watcher, java.nio.file.WatchEvent.Kind<?>... events) throws java.io.IOException
register
in interface java.nio.file.Path
register
in interface java.nio.file.Watchable
java.io.IOException
public java.util.Iterator<java.nio.file.Path> iterator()
iterator
in interface java.lang.Iterable<java.nio.file.Path>
iterator
in interface java.nio.file.Path
public int compareTo(java.nio.file.Path other)
compareTo
in interface java.lang.Comparable<java.nio.file.Path>
compareTo
in interface java.nio.file.Path
public boolean equals(@Nullable java.lang.Object o)
equals
in interface java.nio.file.Path
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.nio.file.Path
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in interface java.nio.file.Path
toString
in class java.lang.Object
public java.lang.String toResourceName()
public java.net.URI toUri()
toUri
in interface java.nio.file.Path