Class CloudStorageFileSystemProvider
- java.lang.Object
-
- java.nio.file.spi.FileSystemProvider
-
- com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider
-
@Singleton @ThreadSafe public final class CloudStorageFileSystemProvider extends FileSystemProvider
Google Cloud StorageFileSystemProvider
implementation.Note: This class should never be used directly. This class is instantiated by the service loader and called through a standardized API, e.g.
Files
. However the javadocs in this class serve as useful documentation for the behavior of the Google Cloud Storage NIO library.
-
-
Constructor Summary
Constructors Constructor Description CloudStorageFileSystemProvider()
Default constructor which should only be called by Java SPI.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkAccess(Path path, AccessMode... modes)
void
copy(Path source, Path target, CopyOption... options)
void
createDirectory(Path dir, FileAttribute<?>... attrs)
Does nothing since Google Cloud Storage uses fake directories.void
delete(Path path)
boolean
deleteIfExists(Path path)
boolean
equals(Object other)
<V extends FileAttributeView>
VgetFileAttributeView(Path path, Class<V> type, LinkOption... options)
FileStore
getFileStore(Path path)
ThrowsUnsupportedOperationException
because this feature hasn't been implemented yet.CloudStorageFileSystem
getFileSystem(URI uri)
Returns Cloud Storage file system, provided a URI with no path, e.g.CloudStoragePath
getPath(String uriInStringForm)
Convenience method: replaces spaces with "%20", builds a URI, and calls getPath(uri).CloudStoragePath
getPath(URI uri)
String
getProject()
Returns the project that is assigned to this provider.String
getScheme()
int
hashCode()
boolean
isHidden(Path path)
Always returnsfalse
, because Google Cloud Storage doesn't support hidden files.boolean
isSameFile(Path path, Path path2)
void
move(Path source, Path target, CopyOption... options)
SeekableByteChannel
newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs)
Open a file for reading or writing.DirectoryStream<Path>
newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)
FileChannel
newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs)
Open a file for reading OR writing.CloudStorageFileSystem
newFileSystem(URI uri, Map<String,?> env)
Returns Cloud Storage file system, provided a URI, e.g.InputStream
newInputStream(Path path, OpenOption... options)
<A extends BasicFileAttributes>
AreadAttributes(Path path, Class<A> type, LinkOption... options)
Map<String,Object>
readAttributes(Path path, String attributes, LinkOption... options)
boolean
requesterPays(String bucketName)
void
setAttribute(Path path, String attribute, Object value, LinkOption... options)
ThrowsUnsupportedOperationException
because Cloud Storage objects are immutable.static void
setDefaultCloudStorageConfiguration(CloudStorageConfiguration newDefault)
Changes the default configuration for every filesystem object created from here on, including via SPI.static void
setStorageOptions(com.google.cloud.storage.StorageOptions newStorageOptions)
Sets options that are only used by the constructor.String
toString()
CloudStorageFileSystemProvider
withNoUserProject()
Returns a NEW CloudStorageFileSystemProvider identical to this one, but with userProject removed.-
Methods inherited from class java.nio.file.spi.FileSystemProvider
createLink, createSymbolicLink, installedProviders, newAsynchronousFileChannel, newFileSystem, newOutputStream, readSymbolicLink
-
-
-
-
Method Detail
-
setStorageOptions
public static void setStorageOptions(@Nullable com.google.cloud.storage.StorageOptions newStorageOptions)
Sets options that are only used by the constructor.Instead of calling this, when possible use CloudStorageFileSystem.forBucket and pass StorageOptions as an argument.
-
setDefaultCloudStorageConfiguration
public static void setDefaultCloudStorageConfiguration(@Nullable CloudStorageConfiguration newDefault)
Changes the default configuration for every filesystem object created from here on, including via SPI. If null then future filesystem objects will have the factory default configuration.If options are specified later then they override the defaults. Methods that take a whole CloudStorageConfiguration (eg. CloudStorageFileSystem.forBucket) will completely override the defaults. Methods that take individual options (eg. CloudStorageFileSystemProvier.newFileSystem) will override only these options; the rest will be taken from the defaults specified here.
This is meant to be done only once, at the beginning of some main program, in order to force all libraries to use some settings we like.
Libraries should never call this. If you're a library then, instead, create your own filesystem object with the right configuration and pass it along.
- Parameters:
newDefault
- new default CloudStorageConfiguration
-
getScheme
public String getScheme()
- Specified by:
getScheme
in classFileSystemProvider
-
getFileSystem
public CloudStorageFileSystem getFileSystem(URI uri)
Returns Cloud Storage file system, provided a URI with no path, e.g.gs://bucket
.- Specified by:
getFileSystem
in classFileSystemProvider
-
newFileSystem
public CloudStorageFileSystem newFileSystem(URI uri, Map<String,?> env)
Returns Cloud Storage file system, provided a URI, e.g.gs://bucket
. The URI can include a path component (that will be ignored).- Specified by:
newFileSystem
in classFileSystemProvider
- Parameters:
uri
- bucket and current working directory, e.g.gs://bucket
env
- map of configuration options, whose keys correspond to the method names ofCloudStorageConfiguration.Builder
. However you are not allowed to set the working directory, as that should be provided in theuri
- Throws:
IllegalArgumentException
- ifuri
specifies a port, user, query, or fragment, or if scheme is not "gs"
-
getPath
public CloudStoragePath getPath(URI uri)
- Specified by:
getPath
in classFileSystemProvider
-
getPath
public CloudStoragePath getPath(String uriInStringForm)
Convenience method: replaces spaces with "%20", builds a URI, and calls getPath(uri).
-
newByteChannel
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
Open a file for reading or writing. To read receiver-pays buckets, specify the BlobSourceOption.userProject option.- Specified by:
newByteChannel
in classFileSystemProvider
- Parameters:
path
- : the path to the file to open or createoptions
- : options specifying how the file is opened, e.g. StandardOpenOption.WRITE or BlobSourceOption.userProjectattrs
- : (not supported, values will be ignored)- Returns:
- Throws:
IOException
-
newFileChannel
public FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
Open a file for reading OR writing. TheFileChannel
that is returned will only allow reads or writes depending on theOpenOption
s that are specified. If any of the following have been specified, theFileChannel
will be write-only:StandardOpenOption.CREATE
StandardOpenOption.CREATE
StandardOpenOption.CREATE_NEW
StandardOpenOption.WRITE
StandardOpenOption.TRUNCATE_EXISTING
FileChannel
will be read-only.- Overrides:
newFileChannel
in classFileSystemProvider
- Parameters:
path
- The path to the file to open or createoptions
- The options specifying how the file should be opened, and whether theFileChannel
should be read-only or write-only.attrs
- (not supported, the values will be ignored)- Throws:
IOException
-
newInputStream
public InputStream newInputStream(Path path, OpenOption... options) throws IOException
- Overrides:
newInputStream
in classFileSystemProvider
- Throws:
IOException
-
deleteIfExists
public boolean deleteIfExists(Path path) throws IOException
- Overrides:
deleteIfExists
in classFileSystemProvider
- Throws:
IOException
-
delete
public void delete(Path path) throws IOException
- Specified by:
delete
in classFileSystemProvider
- Throws:
IOException
-
move
public void move(Path source, Path target, CopyOption... options) throws IOException
- Specified by:
move
in classFileSystemProvider
- Throws:
IOException
-
copy
public void copy(Path source, Path target, CopyOption... options) throws IOException
- Specified by:
copy
in classFileSystemProvider
- Throws:
IOException
-
isSameFile
public boolean isSameFile(Path path, Path path2)
- Specified by:
isSameFile
in classFileSystemProvider
-
isHidden
public boolean isHidden(Path path)
Always returnsfalse
, because Google Cloud Storage doesn't support hidden files.- Specified by:
isHidden
in classFileSystemProvider
-
checkAccess
public void checkAccess(Path path, AccessMode... modes) throws IOException
- Specified by:
checkAccess
in classFileSystemProvider
- Throws:
IOException
-
readAttributes
public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException
- Specified by:
readAttributes
in classFileSystemProvider
- Throws:
IOException
-
readAttributes
public Map<String,Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException
- Specified by:
readAttributes
in classFileSystemProvider
- Throws:
IOException
-
getFileAttributeView
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options)
- Specified by:
getFileAttributeView
in classFileSystemProvider
-
createDirectory
public void createDirectory(Path dir, FileAttribute<?>... attrs)
Does nothing since Google Cloud Storage uses fake directories.- Specified by:
createDirectory
in classFileSystemProvider
-
newDirectoryStream
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)
- Specified by:
newDirectoryStream
in classFileSystemProvider
-
setAttribute
public void setAttribute(Path path, String attribute, Object value, LinkOption... options)
ThrowsUnsupportedOperationException
because Cloud Storage objects are immutable.- Specified by:
setAttribute
in classFileSystemProvider
-
getFileStore
public FileStore getFileStore(Path path)
ThrowsUnsupportedOperationException
because this feature hasn't been implemented yet.- Specified by:
getFileStore
in classFileSystemProvider
-
requesterPays
public boolean requesterPays(String bucketName)
- Parameters:
bucketName
- the name of the bucket to check- Returns:
- whether requester pays is enabled for that bucket
-
withNoUserProject
public CloudStorageFileSystemProvider withNoUserProject()
Returns a NEW CloudStorageFileSystemProvider identical to this one, but with userProject removed.Perhaps you want to call this is you realize you'll be working on a bucket that is not requester-pays.
-
getProject
public String getProject()
Returns the project that is assigned to this provider.
-
-