Class CloudStorageFileSystem (0.127.22)

public final class CloudStorageFileSystem extends FileSystem

Google Cloud Storage FileSystem implementation. See Also: Concepts and Terminology, Bucket and Object Naming Guidelines

Inheritance

Object > FileSystem > CloudStorageFileSystem

Static Fields

BASIC_VIEW

public static final String BASIC_VIEW
Field Value
Type Description
String

BLOCK_SIZE_DEFAULT

public static final int BLOCK_SIZE_DEFAULT
Field Value
Type Description
int

FILE_TIME_UNKNOWN

public static final FileTime FILE_TIME_UNKNOWN
Field Value
Type Description
FileTime

GCS_VIEW

public static final String GCS_VIEW
Field Value
Type Description
String

POSIX_VIEW

public static final String POSIX_VIEW
Field Value
Type Description
String

SUPPORTED_VIEWS

public static final Set<String> SUPPORTED_VIEWS
Field Value
Type Description
Set<String>

URI_SCHEME

public static final String URI_SCHEME
Field Value
Type Description
String

Static Methods

forBucket(String bucket)

public static CloudStorageFileSystem forBucket(String bucket)

Returns Google Cloud Storage FileSystem object for bucket.

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. See Also: #forBucket(String, CloudStorageConfiguration), java.nio.file.FileSystems#getFileSystem(java.net.URI)

Parameter
Name Description
bucket String
Returns
Type Description
CloudStorageFileSystem

forBucket(String bucket, CloudStorageConfiguration config)

public static CloudStorageFileSystem forBucket(String bucket, CloudStorageConfiguration config)

Creates new file system instance for bucket, with customizable settings. See Also: #forBucket(String)

Parameters
Name Description
bucket String
config CloudStorageConfiguration
Returns
Type Description
CloudStorageFileSystem

forBucket(String bucket, CloudStorageConfiguration config, StorageOptions storageOptions)

public static CloudStorageFileSystem forBucket(String bucket, CloudStorageConfiguration config, StorageOptions storageOptions)

Returns Google Cloud Storage FileSystem object for bucket.

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 in CloudStorageFileSystemProvider#newFileSystem(URI, java.util.Map) See Also: java.nio.file.FileSystems#getFileSystem(URI)

Parameters
Name Description
bucket String
config CloudStorageConfiguration
storageOptions com.google.cloud.storage.StorageOptions
Returns
Type Description
CloudStorageFileSystem

listBuckets(String project, Storage.BucketListOption[] options)

public static Page<Bucket> listBuckets(String project, 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
 }
 
Parameters
Name Description
project String
options com.google.cloud.storage.Storage.BucketListOption[]
Returns
Type Description
Page<com.google.cloud.storage.Bucket>

Methods

bucket()

public String bucket()

Returns Cloud Storage bucket name being served by this file system.

Returns
Type Description
String

close()

public void close()

Does 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.

Overrides
Exceptions
Type Description
IOException

config()

public CloudStorageConfiguration config()

Returns configuration object for this file system instance.

Returns
Type Description
CloudStorageConfiguration

equals(Object other)

public boolean equals(Object other)
Parameter
Name Description
other Object
Returns
Type Description
boolean
Overrides

getFileStores()

public Iterable<FileStore> getFileStores()

Returns nothing because Google Cloud Storage doesn't have disk partitions of limited size, or anything similar.

Returns
Type Description
Iterable<FileStore>
Overrides

getPath(String first, String[] more)

public CloudStoragePath getPath(String first, String[] more)

Converts Cloud Storage object name to a Path object.

Parameters
Name Description
first String
more String[]
Returns
Type Description
CloudStoragePath
Overrides

getPathMatcher(String syntaxAndPattern)

public PathMatcher getPathMatcher(String syntaxAndPattern)
Parameter
Name Description
syntaxAndPattern String
Returns
Type Description
PathMatcher
Overrides

getRootDirectories()

public Iterable<Path> getRootDirectories()
Returns
Type Description
Iterable<Path>
Overrides

getSeparator()

public String getSeparator()

Returns {@value UnixPath#SEPARATOR}.

Returns
Type Description
String
Overrides

getUserPrincipalLookupService()

public UserPrincipalLookupService getUserPrincipalLookupService()

Throws UnsupportedOperationException because this feature hasn't been implemented yet.

Returns
Type Description
UserPrincipalLookupService
Overrides

hashCode()

public int hashCode()
Returns
Type Description
int
Overrides

isOpen()

public boolean isOpen()

Returns true, even if you previously called the #close() method.

Returns
Type Description
boolean
Overrides

isReadOnly()

public boolean isReadOnly()

Returns false.

Returns
Type Description
boolean
Overrides

newWatchService()

public WatchService newWatchService()

Throws UnsupportedOperationException because this feature hasn't been implemented yet.

Returns
Type Description
WatchService
Overrides
Exceptions
Type Description
IOException

provider()

public CloudStorageFileSystemProvider provider()
Returns
Type Description
CloudStorageFileSystemProvider
Overrides

supportedFileAttributeViews()

public Set<String> supportedFileAttributeViews()
Returns
Type Description
Set<String>
Overrides

toString()

public String toString()
Returns
Type Description
String
Overrides