Class CloudStorageFileSystem (0.125.0)

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
TypeDescription
String

BLOCK_SIZE_DEFAULT

public static final int BLOCK_SIZE_DEFAULT
Field Value
TypeDescription
int

FILE_TIME_UNKNOWN

public static final FileTime FILE_TIME_UNKNOWN
Field Value
TypeDescription
FileTime

GCS_VIEW

public static final String GCS_VIEW
Field Value
TypeDescription
String

SUPPORTED_VIEWS

public static final Set<String> SUPPORTED_VIEWS
Field Value
TypeDescription
Set<String>

URI_SCHEME

public static final String URI_SCHEME
Field Value
TypeDescription
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
NameDescription
bucketString
Returns
TypeDescription
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
NameDescription
bucketString
configCloudStorageConfiguration
Returns
TypeDescription
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
NameDescription
bucketString
configCloudStorageConfiguration
storageOptionscom.google.cloud.storage.StorageOptions
Returns
TypeDescription
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
NameDescription
projectString
optionscom.google.cloud.storage.Storage.BucketListOption[]
Returns
TypeDescription
Page<com.google.cloud.storage.Bucket>

Methods

bucket()

public String bucket()

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

Returns
TypeDescription
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
TypeDescription
IOException

config()

public CloudStorageConfiguration config()

Returns configuration object for this file system instance.

Returns
TypeDescription
CloudStorageConfiguration

equals(Object other)

public boolean equals(Object other)
Parameter
NameDescription
otherObject
Returns
TypeDescription
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
TypeDescription
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
NameDescription
firstString
moreString[]
Returns
TypeDescription
CloudStoragePath
Overrides

getPathMatcher(String syntaxAndPattern)

public PathMatcher getPathMatcher(String syntaxAndPattern)
Parameter
NameDescription
syntaxAndPatternString
Returns
TypeDescription
PathMatcher
Overrides

getRootDirectories()

public Iterable<Path> getRootDirectories()
Returns
TypeDescription
Iterable<Path>
Overrides

getSeparator()

public String getSeparator()

Returns {@value UnixPath#SEPARATOR}.

Returns
TypeDescription
String
Overrides

getUserPrincipalLookupService()

public UserPrincipalLookupService getUserPrincipalLookupService()

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

Returns
TypeDescription
UserPrincipalLookupService
Overrides

hashCode()

public int hashCode()
Returns
TypeDescription
int
Overrides

isOpen()

public boolean isOpen()

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

Returns
TypeDescription
boolean
Overrides

isReadOnly()

public boolean isReadOnly()

Returns false.

Returns
TypeDescription
boolean
Overrides

newWatchService()

public WatchService newWatchService()

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

Returns
TypeDescription
WatchService
Overrides Exceptions
TypeDescription
IOException

provider()

public CloudStorageFileSystemProvider provider()
Returns
TypeDescription
CloudStorageFileSystemProvider
Overrides

supportedFileAttributeViews()

public Set<String> supportedFileAttributeViews()
Returns
TypeDescription
Set<String>
Overrides

toString()

public String toString()
Returns
TypeDescription
String
Overrides