Class CloudStoragePath
- java.lang.Object
-
- com.google.cloud.storage.contrib.nio.CloudStoragePath
-
@Immutable public final class CloudStoragePath extends Object implements Path
A Google Cloud Storage specific implementation of thejava.nio.file.Path
interface. An instance of this class locates an object or a "pseudo-directory" in GCS. This implementation allows one to use Java's standard file system API to deal with remote objects as if they are local files.Example of using
java.nio.file.Files
to read all lines from a remote object:Path path = Paths.get(URI.create("gs://bucket/lolcat.csv")); List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
bucket()
Returns the Cloud Storage bucket name being served by this file system.int
compareTo(Path other)
boolean
endsWith(String other)
boolean
endsWith(Path other)
boolean
equals(Object other)
CloudStoragePath
getFileName()
CloudStorageFileSystem
getFileSystem()
CloudStoragePath
getName(int index)
int
getNameCount()
CloudStoragePath
getParent()
CloudStoragePath
getRoot()
int
hashCode()
boolean
isAbsolute()
Iterator<Path>
iterator()
CloudStoragePath
normalize()
Returns path without extra slashes or.
and..
and preserves trailing slash.WatchKey
register(WatchService watcher, WatchEvent.Kind<?>... events)
ThrowsUnsupportedOperationException
because this feature hasn't been implemented yet.WatchKey
register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers)
ThrowsUnsupportedOperationException
because this feature hasn't been implemented yet.CloudStoragePath
relativize(Path object)
CloudStoragePath
resolve(String other)
CloudStoragePath
resolve(Path object)
CloudStoragePath
resolveSibling(String other)
CloudStoragePath
resolveSibling(Path other)
boolean
startsWith(String other)
boolean
startsWith(Path other)
CloudStoragePath
subpath(int beginIndex, int endIndex)
CloudStoragePath
toAbsolutePath()
Changes relative path to be absolute, usingworkingDirectory
as current dir.File
toFile()
ThrowsUnsupportedOperationException
because Google Cloud Storage files are not backed by the local file system.CloudStoragePath
toRealPath(LinkOption... options)
Returns this path rewritten to the Cloud Storage object name that'd be used to perform i/o.String
toString()
URI
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
-
-
-
-
Method Detail
-
bucket
public String bucket()
Returns the Cloud Storage bucket name being served by this file system.
-
getFileSystem
public CloudStorageFileSystem getFileSystem()
- Specified by:
getFileSystem
in interfacePath
-
getRoot
@Nullable public CloudStoragePath getRoot()
-
isAbsolute
public boolean isAbsolute()
- Specified by:
isAbsolute
in interfacePath
-
toAbsolutePath
public CloudStoragePath toAbsolutePath()
Changes relative path to be absolute, usingworkingDirectory
as current dir.- Specified by:
toAbsolutePath
in interfacePath
-
toRealPath
public CloudStoragePath toRealPath(LinkOption... options)
Returns this path rewritten to the Cloud Storage object name that'd be used to perform i/o.This method makes path
absolute
and removes the prefix slash from the absolute path whenstripPrefixSlash
istrue
.- Specified by:
toRealPath
in interfacePath
- Throws:
IllegalArgumentException
- if path contains extra slashes or dot-dirs whenpermitEmptyPathComponents
isfalse
, or if the resulting path is empty.
-
normalize
public CloudStoragePath normalize()
Returns path without extra slashes or.
and..
and preserves trailing slash.
-
resolve
public CloudStoragePath resolve(Path object)
-
resolve
public CloudStoragePath resolve(String other)
-
resolveSibling
public CloudStoragePath resolveSibling(Path other)
- Specified by:
resolveSibling
in interfacePath
-
resolveSibling
public CloudStoragePath resolveSibling(String other)
- Specified by:
resolveSibling
in interfacePath
-
relativize
public CloudStoragePath relativize(Path object)
- Specified by:
relativize
in interfacePath
-
getParent
@Nullable public CloudStoragePath getParent()
-
getFileName
@Nullable public CloudStoragePath getFileName()
- Specified by:
getFileName
in interfacePath
-
subpath
public CloudStoragePath subpath(int beginIndex, int endIndex)
-
getNameCount
public int getNameCount()
- Specified by:
getNameCount
in interfacePath
-
getName
public CloudStoragePath getName(int index)
-
startsWith
public boolean startsWith(Path other)
- Specified by:
startsWith
in interfacePath
-
startsWith
public boolean startsWith(String other)
- Specified by:
startsWith
in interfacePath
-
register
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers)
ThrowsUnsupportedOperationException
because this feature hasn't been implemented yet.
-
register
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events)
ThrowsUnsupportedOperationException
because this feature hasn't been implemented yet.
-
toFile
public File toFile()
ThrowsUnsupportedOperationException
because Google Cloud Storage files are not backed by the local file system.
-
compareTo
public int compareTo(Path other)
- Specified by:
compareTo
in interfaceComparable<Path>
- Specified by:
compareTo
in interfacePath
-
equals
public boolean equals(Object other)
-
hashCode
public int hashCode()
-
toString
public String toString()
-
-