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 StorageFileSystem
implementation.
-
-
Field Summary
Fields Modifier and Type Field Description static String
BASIC_VIEW
static int
BLOCK_SIZE_DEFAULT
static FileTime
FILE_TIME_UNKNOWN
static String
GCS_VIEW
static String
POSIX_VIEW
static Set<String>
SUPPORTED_VIEWS
static String
URI_SCHEME
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
bucket()
Returns Cloud Storage bucket name being served by this file system.void
close()
Does nothing currently.CloudStorageConfiguration
config()
Returns configuration object for this file system instance.boolean
equals(Object other)
static CloudStorageFileSystem
forBucket(String bucket)
Returns Google Cloud StorageFileSystem
object forbucket
.static CloudStorageFileSystem
forBucket(String bucket, CloudStorageConfiguration config)
Creates new file system instance forbucket
, with customizable settings.static CloudStorageFileSystem
forBucket(String bucket, CloudStorageConfiguration config, com.google.cloud.storage.StorageOptions storageOptions)
Returns Google Cloud StorageFileSystem
object forbucket
.Iterable<FileStore>
getFileStores()
Returns nothing because Google Cloud Storage doesn't have disk partitions of limited size, or anything similar.CloudStoragePath
getPath(String first, String... more)
Converts Cloud Storage object name to aPath
object.PathMatcher
getPathMatcher(String syntaxAndPattern)
Iterable<Path>
getRootDirectories()
String
getSeparator()
Returns 47.UserPrincipalLookupService
getUserPrincipalLookupService()
ThrowsUnsupportedOperationException
because this feature hasn't been implemented yet.int
hashCode()
boolean
isOpen()
Returnstrue
, even if you previously called theclose()
method.boolean
isReadOnly()
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.WatchService
newWatchService()
ThrowsUnsupportedOperationException
because this feature hasn't been implemented yet.CloudStorageFileSystemProvider
provider()
Set<String>
supportedFileAttributeViews()
String
toString()
-
-
-
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 StorageFileSystem
object 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 StorageFileSystem
object 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:
provider
in 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 aPath
object.- Specified by:
getPath
in classFileSystem
-
close
public void close() throws IOException
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.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classFileSystem
- Throws:
IOException
-
isOpen
public boolean isOpen()
Returnstrue
, even if you previously called theclose()
method.- Specified by:
isOpen
in classFileSystem
-
isReadOnly
public boolean isReadOnly()
Returnsfalse
.- Specified by:
isReadOnly
in classFileSystem
-
getSeparator
public String getSeparator()
Returns 47.- Specified by:
getSeparator
in classFileSystem
-
getRootDirectories
public Iterable<Path> getRootDirectories()
- Specified by:
getRootDirectories
in 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:
getFileStores
in classFileSystem
-
supportedFileAttributeViews
public Set<String> supportedFileAttributeViews()
- Specified by:
supportedFileAttributeViews
in classFileSystem
-
getPathMatcher
public PathMatcher getPathMatcher(String syntaxAndPattern)
- Specified by:
getPathMatcher
in classFileSystem
-
getUserPrincipalLookupService
public UserPrincipalLookupService getUserPrincipalLookupService()
ThrowsUnsupportedOperationException
because this feature hasn't been implemented yet.- Specified by:
getUserPrincipalLookupService
in classFileSystem
-
newWatchService
public WatchService newWatchService() throws IOException
ThrowsUnsupportedOperationException
because this feature hasn't been implemented yet.- Specified by:
newWatchService
in classFileSystem
- Throws:
IOException
-
-