public class GcsPath extends Object implements Path, 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 Pattern |
GCS_URI
Pattern that is used to parse a GCS URL.
|
static String |
SCHEME |
| Constructor and Description |
|---|
GcsPath(FileSystem fs,
String bucket,
String object)
Constructs a GcsPath.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Path other) |
boolean |
endsWith(Path other) |
boolean |
endsWith(String suffix) |
boolean |
equals(Object o) |
static GcsPath |
fromComponents(String bucket,
String object)
Creates a GcsPath from bucket and object components.
|
static GcsPath |
fromObject(com.google.api.services.storage.model.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 |
fromUri(String uri)
Creates a GcsPath from a URI in string form.
|
static GcsPath |
fromUri(URI uri)
Creates a GcsPath from a URI.
|
String |
getBucket()
Returns the bucket name associated with this GCS path, or an empty string
if this is a relative path component.
|
GcsPath |
getFileName() |
FileSystem |
getFileSystem() |
GcsPath |
getName(int count) |
int |
getNameCount() |
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() |
Iterator<Path> |
iterator() |
GcsPath |
normalize() |
WatchKey |
register(WatchService watcher,
WatchEvent.Kind<?>... events) |
WatchKey |
register(WatchService watcher,
WatchEvent.Kind<?>[] events,
WatchEvent.Modifier... modifiers) |
Path |
relativize(Path other) |
GcsPath |
resolve(Path other) |
GcsPath |
resolve(String other) |
Path |
resolveSibling(Path other) |
Path |
resolveSibling(String other) |
void |
setFileSystem(FileSystem fs) |
boolean |
startsWith(Path other) |
boolean |
startsWith(String prefix) |
GcsPath |
subpath(int beginIndex,
int endIndex) |
GcsPath |
toAbsolutePath() |
File |
toFile() |
GcsPath |
toRealPath(LinkOption... options) |
String |
toResourceName() |
String |
toString() |
URI |
toUri() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic static final String SCHEME
public static final Pattern GCS_URI
This is used to separate the components. Verification is handled separately.
public GcsPath(@Nullable FileSystem fs, @Nullable String bucket, @Nullable 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 objectIllegalArgumentException - if the bucket of object names
are invalid.public static GcsPath fromUri(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(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(String name)
public static GcsPath fromObject(com.google.api.services.storage.model.StorageObject object)
public static GcsPath fromComponents(@Nullable String bucket, @Nullable 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 String getBucket()
public String getObject()
public void setFileSystem(FileSystem fs)
public FileSystem getFileSystem()
getFileSystem in interface Pathpublic boolean isAbsolute()
isAbsolute in interface Pathpublic GcsPath getFileName()
getFileName in interface Pathpublic 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.
public int getNameCount()
getNameCount in interface Pathpublic GcsPath subpath(int beginIndex, int endIndex)
public boolean startsWith(Path other)
startsWith in interface Pathpublic boolean startsWith(String prefix)
startsWith in interface Pathpublic Path resolveSibling(Path other)
resolveSibling in interface Pathpublic Path resolveSibling(String other)
resolveSibling in interface Pathpublic Path relativize(Path other)
relativize in interface Pathpublic GcsPath toAbsolutePath()
toAbsolutePath in interface Pathpublic GcsPath toRealPath(LinkOption... options) throws IOException
toRealPath in interface PathIOExceptionpublic WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException
register in interface Pathregister in interface WatchableIOExceptionpublic WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) throws IOException
register in interface Pathregister in interface WatchableIOExceptionpublic int compareTo(Path other)
compareTo in interface Comparable<Path>compareTo in interface Pathpublic boolean equals(Object o)
public int hashCode()
public String toString()
public String toResourceName()
Copyright © 2016–2017 The Apache Software Foundation. All rights reserved.