Class CloudStorageFileSystem
- java.lang.Object
-
- java.nio.file.FileSystem
-
- com.google.cloud.storage.contrib.nio.CloudStorageFileSystem
-
- All Implemented Interfaces:
Closeable,AutoCloseable
@ThreadSafe public final class CloudStorageFileSystem extends FileSystem
Google Cloud StorageFileSystemimplementation.
-
-
Field Summary
Fields Modifier and Type Field Description static StringBASIC_VIEWstatic intBLOCK_SIZE_DEFAULTstatic FileTimeFILE_TIME_UNKNOWNstatic StringGCS_VIEWstatic StringPOSIX_VIEWstatic Set<String>SUPPORTED_VIEWSstatic StringURI_SCHEME
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringbucket()Returns Cloud Storage bucket name being served by this file system.voidclose()Does nothing currently.CloudStorageConfigurationconfig()Returns configuration object for this file system instance.booleanequals(Object other)static CloudStorageFileSystemforBucket(String bucket)Returns Google Cloud StorageFileSystemobject forbucket.static CloudStorageFileSystemforBucket(String bucket, CloudStorageConfiguration config)Creates new file system instance forbucket, with customizable settings.static CloudStorageFileSystemforBucket(String bucket, CloudStorageConfiguration config, com.google.cloud.storage.StorageOptions storageOptions)Returns Google Cloud StorageFileSystemobject forbucket.Iterable<FileStore>getFileStores()Returns nothing because Google Cloud Storage doesn't have disk partitions of limited size, or anything similar.CloudStoragePathgetPath(String first, String... more)Converts Cloud Storage object name to aPathobject.PathMatchergetPathMatcher(String syntaxAndPattern)Iterable<Path>getRootDirectories()StringgetSeparator()Returns 47.UserPrincipalLookupServicegetUserPrincipalLookupService()ThrowsUnsupportedOperationExceptionbecause this feature hasn't been implemented yet.inthashCode()booleanisOpen()Returnstrue, even if you previously called theclose()method.booleanisReadOnly()Returnsfalse.static com.google.api.gax.paging.Page<com.google.cloud.storage.Bucket>listBuckets(String project, com.google.cloud.storage.Storage.BucketListOption... options)Lists the project's buckets.WatchServicenewWatchService()ThrowsUnsupportedOperationExceptionbecause this feature hasn't been implemented yet.CloudStorageFileSystemProviderprovider()Set<String>supportedFileAttributeViews()StringtoString()
-
-
-
Field Detail
-
URI_SCHEME
public static final String URI_SCHEME
- See Also:
- Constant Field Values
-
GCS_VIEW
public static final String GCS_VIEW
- See Also:
- Constant Field Values
-
BASIC_VIEW
public static final String BASIC_VIEW
- See Also:
- Constant Field Values
-
POSIX_VIEW
public static final String POSIX_VIEW
- See Also:
- Constant Field Values
-
BLOCK_SIZE_DEFAULT
public static final int BLOCK_SIZE_DEFAULT
- See Also:
- Constant Field Values
-
FILE_TIME_UNKNOWN
public static final FileTime FILE_TIME_UNKNOWN
-
-
Method Detail
-
listBuckets
public static com.google.api.gax.paging.Page<com.google.cloud.storage.Bucket> listBuckets(@Nullable String project, com.google.cloud.storage.Storage.BucketListOption... options)
Lists the project's buckets. Pass "null" to use the default project.Example of listing buckets, specifying the page size and a name prefix.
String prefix = "bucket_"; Page<Bucket> buckets = CloudStorageFileSystem.listBuckets("my-project", BucketListOption.prefix(prefix)); Iterator<Bucket> bucketIterator = buckets.iterateAll(); while (bucketIterator.hasNext()) { Bucket bucket = bucketIterator.next(); // do something with the bucket }- Throws:
com.google.cloud.storage.StorageException- upon failure
-
forBucket
@CheckReturnValue public static CloudStorageFileSystem forBucket(String bucket)
Returns Google Cloud StorageFileSystemobject forbucket.NOTE: You may prefer to use Java's standard API instead:
FileSystem fs = FileSystems.getFileSystem(URI.create("gs://bucket"));However some systems and build environments might be flaky when it comes to Java SPI. This is because services are generally runtime dependencies and depend on a META-INF file being present in your jar (generated by Google Auto at compile-time). In such cases, this method provides a simpler alternative.
-
forBucket
@CheckReturnValue public static CloudStorageFileSystem forBucket(String bucket, CloudStorageConfiguration config)
Creates new file system instance forbucket, with customizable settings.- See Also:
forBucket(String)
-
forBucket
@CheckReturnValue public static CloudStorageFileSystem forBucket(String bucket, CloudStorageConfiguration config, @Nullable com.google.cloud.storage.StorageOptions storageOptions)
Returns Google Cloud StorageFileSystemobject forbucket.Google Cloud Storage file system objects are basically free. You can create as many as you want, even if you have multiple instances for the same bucket. There's no actual system resources associated with this object. Therefore calling
close()on the returned value is optional.Note: It is also possible to instantiate this class via Java's
FileSystems.getFileSystem(URI.create("gs://bucket")). We discourage you from using that if possible, for the reasons documented inCloudStorageFileSystemProvider.newFileSystem(URI, java.util.Map)- See Also:
FileSystems.getFileSystem(URI)
-
provider
public CloudStorageFileSystemProvider provider()
- Specified by:
providerin classFileSystem
-
bucket
public String bucket()
Returns Cloud Storage bucket name being served by this file system.
-
config
public CloudStorageConfiguration config()
Returns configuration object for this file system instance.
-
getPath
public CloudStoragePath getPath(String first, String... more)
Converts Cloud Storage object name to aPathobject.- Specified by:
getPathin classFileSystem
-
close
public void close() throws IOExceptionDoes nothing currently. This method might be updated in the future to close all channels associated with this file system object. However it's unlikely that even then, calling this method will become mandatory.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classFileSystem- Throws:
IOException
-
isOpen
public boolean isOpen()
Returnstrue, even if you previously called theclose()method.- Specified by:
isOpenin classFileSystem
-
isReadOnly
public boolean isReadOnly()
Returnsfalse.- Specified by:
isReadOnlyin classFileSystem
-
getSeparator
public String getSeparator()
Returns 47.- Specified by:
getSeparatorin classFileSystem
-
getRootDirectories
public Iterable<Path> getRootDirectories()
- Specified by:
getRootDirectoriesin classFileSystem
-
getFileStores
public Iterable<FileStore> getFileStores()
Returns nothing because Google Cloud Storage doesn't have disk partitions of limited size, or anything similar.- Specified by:
getFileStoresin classFileSystem
-
supportedFileAttributeViews
public Set<String> supportedFileAttributeViews()
- Specified by:
supportedFileAttributeViewsin classFileSystem
-
getPathMatcher
public PathMatcher getPathMatcher(String syntaxAndPattern)
- Specified by:
getPathMatcherin classFileSystem
-
getUserPrincipalLookupService
public UserPrincipalLookupService getUserPrincipalLookupService()
ThrowsUnsupportedOperationExceptionbecause this feature hasn't been implemented yet.- Specified by:
getUserPrincipalLookupServicein classFileSystem
-
newWatchService
public WatchService newWatchService() throws IOException
ThrowsUnsupportedOperationExceptionbecause this feature hasn't been implemented yet.- Specified by:
newWatchServicein classFileSystem- Throws:
IOException
-
-