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.Pathinterface. 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.Filesto 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 Stringbucket()Returns the Cloud Storage bucket name being served by this file system.intcompareTo(Path other)booleanendsWith(String other)booleanendsWith(Path other)booleanequals(Object other)CloudStoragePathgetFileName()CloudStorageFileSystemgetFileSystem()CloudStoragePathgetName(int index)intgetNameCount()CloudStoragePathgetParent()CloudStoragePathgetRoot()inthashCode()booleanisAbsolute()Iterator<Path>iterator()CloudStoragePathnormalize()Returns path without extra slashes or.and..and preserves trailing slash.WatchKeyregister(WatchService watcher, WatchEvent.Kind<?>... events)ThrowsUnsupportedOperationExceptionbecause this feature hasn't been implemented yet.WatchKeyregister(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers)ThrowsUnsupportedOperationExceptionbecause this feature hasn't been implemented yet.CloudStoragePathrelativize(Path object)CloudStoragePathresolve(String other)CloudStoragePathresolve(Path object)CloudStoragePathresolveSibling(String other)CloudStoragePathresolveSibling(Path other)booleanstartsWith(String other)booleanstartsWith(Path other)CloudStoragePathsubpath(int beginIndex, int endIndex)CloudStoragePathtoAbsolutePath()Changes relative path to be absolute, usingworkingDirectoryas current dir.FiletoFile()ThrowsUnsupportedOperationExceptionbecause Google Cloud Storage files are not backed by the local file system.CloudStoragePathtoRealPath(LinkOption... options)Returns this path rewritten to the Cloud Storage object name that'd be used to perform i/o.StringtoString()URItoUri()-
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:
getFileSystemin interfacePath
-
getRoot
@Nullable public CloudStoragePath getRoot()
-
isAbsolute
public boolean isAbsolute()
- Specified by:
isAbsolutein interfacePath
-
toAbsolutePath
public CloudStoragePath toAbsolutePath()
Changes relative path to be absolute, usingworkingDirectoryas current dir.- Specified by:
toAbsolutePathin 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
absoluteand removes the prefix slash from the absolute path whenstripPrefixSlashistrue.- Specified by:
toRealPathin interfacePath- Throws:
IllegalArgumentException- if path contains extra slashes or dot-dirs whenpermitEmptyPathComponentsisfalse, 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:
resolveSiblingin interfacePath
-
resolveSibling
public CloudStoragePath resolveSibling(String other)
- Specified by:
resolveSiblingin interfacePath
-
relativize
public CloudStoragePath relativize(Path object)
- Specified by:
relativizein interfacePath
-
getParent
@Nullable public CloudStoragePath getParent()
-
getFileName
@Nullable public CloudStoragePath getFileName()
- Specified by:
getFileNamein interfacePath
-
subpath
public CloudStoragePath subpath(int beginIndex, int endIndex)
-
getNameCount
public int getNameCount()
- Specified by:
getNameCountin interfacePath
-
getName
public CloudStoragePath getName(int index)
-
startsWith
public boolean startsWith(Path other)
- Specified by:
startsWithin interfacePath
-
startsWith
public boolean startsWith(String other)
- Specified by:
startsWithin interfacePath
-
register
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers)
ThrowsUnsupportedOperationExceptionbecause this feature hasn't been implemented yet.
-
register
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events)
ThrowsUnsupportedOperationExceptionbecause this feature hasn't been implemented yet.
-
toFile
public File toFile()
ThrowsUnsupportedOperationExceptionbecause Google Cloud Storage files are not backed by the local file system.
-
compareTo
public int compareTo(Path other)
- Specified by:
compareToin interfaceComparable<Path>- Specified by:
compareToin interfacePath
-
equals
public boolean equals(Object other)
-
hashCode
public int hashCode()
-
toString
public String toString()
-
-