Class CloudStorageFileSystemProvider
FileSystemProvider 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
ConstructorsConstructorDescriptionDefault constructor which should only be called by Java SPI. -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckAccess(Path path, AccessMode... modes) voidcopy(Path source, Path target, CopyOption... options) voidcreateDirectory(Path dir, FileAttribute<?>... attrs) Does nothing since Google Cloud Storage uses fake directories.voidbooleandeleteIfExists(Path path) boolean<V extends FileAttributeView>
VgetFileAttributeView(Path path, Class<V> type, LinkOption... options) getFileStore(Path path) ThrowsUnsupportedOperationExceptionbecause this feature hasn't been implemented yet.getFileSystem(URI uri) Returns Cloud Storage file system, provided a URI with no path, e.g.Convenience method: replaces spaces with "%20", builds a URI, and calls getPath(uri).Returns the project that is assigned to this provider.inthashCode()booleanAlways returnsfalse, because Google Cloud Storage doesn't support hidden files.booleanisSameFile(Path path, Path path2) voidmove(Path source, Path target, CopyOption... options) newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) Open a file for reading or writing.newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) Open a file for reading OR writing.newFileSystem(URI uri, Map<String, ?> env) Returns Cloud Storage file system, provided a URI, e.g.newInputStream(Path path, OpenOption... options) <A extends BasicFileAttributes>
AreadAttributes(Path path, Class<A> type, LinkOption... options) readAttributes(Path path, String attributes, LinkOption... options) booleanrequesterPays(String bucketName) voidsetAttribute(Path path, String attribute, Object value, LinkOption... options) ThrowsUnsupportedOperationExceptionbecause Cloud Storage objects are immutable.static voidChanges the default configuration for every filesystem object created from here on, including via SPI.static voidsetStorageOptions(com.google.cloud.storage.StorageOptions newStorageOptions) Sets options that are only used by the constructor.toString()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
-
Constructor Details
-
CloudStorageFileSystemProvider
public CloudStorageFileSystemProvider()Default constructor which should only be called by Java SPI.
-
-
Method Details
-
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
- Specified by:
getSchemein classFileSystemProvider
-
getFileSystem
Returns Cloud Storage file system, provided a URI with no path, e.g.gs://bucket.- Specified by:
getFileSystemin classFileSystemProvider
-
newFileSystem
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:
newFileSystemin classFileSystemProvider- Parameters:
uri- bucket and current working directory, e.g.gs://bucketenv- 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- ifurispecifies a port, user, query, or fragment, or if scheme is not "gs"
-
getPath
- Specified by:
getPathin classFileSystemProvider
-
getPath
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:
newByteChannelin 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. TheFileChannelthat is returned will only allow reads or writes depending on theOpenOptions that are specified. If any of the following have been specified, theFileChannelwill be write-only:StandardOpenOption.CREATEStandardOpenOption.CREATEStandardOpenOption.CREATE_NEWStandardOpenOption.WRITEStandardOpenOption.TRUNCATE_EXISTING
FileChannelwill be read-only.- Overrides:
newFileChannelin classFileSystemProvider- Parameters:
path- The path to the file to open or createoptions- The options specifying how the file should be opened, and whether theFileChannelshould be read-only or write-only.attrs- (not supported, the values will be ignored)- Throws:
IOException
-
newInputStream
- Overrides:
newInputStreamin classFileSystemProvider- Throws:
IOException
-
deleteIfExists
- Overrides:
deleteIfExistsin classFileSystemProvider- Throws:
IOException
-
delete
- Specified by:
deletein classFileSystemProvider- Throws:
IOException
-
move
- Specified by:
movein classFileSystemProvider- Throws:
IOException
-
copy
- Specified by:
copyin classFileSystemProvider- Throws:
IOException
-
isSameFile
- Specified by:
isSameFilein classFileSystemProvider
-
isHidden
Always returnsfalse, because Google Cloud Storage doesn't support hidden files.- Specified by:
isHiddenin classFileSystemProvider
-
checkAccess
- Specified by:
checkAccessin classFileSystemProvider- Throws:
IOException
-
readAttributes
public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException - Specified by:
readAttributesin classFileSystemProvider- Throws:
IOException
-
readAttributes
public Map<String,Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException - Specified by:
readAttributesin classFileSystemProvider- Throws:
IOException
-
getFileAttributeView
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) - Specified by:
getFileAttributeViewin classFileSystemProvider
-
createDirectory
Does nothing since Google Cloud Storage uses fake directories.- Specified by:
createDirectoryin classFileSystemProvider
-
newDirectoryStream
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) - Specified by:
newDirectoryStreamin classFileSystemProvider
-
setAttribute
ThrowsUnsupportedOperationExceptionbecause Cloud Storage objects are immutable.- Specified by:
setAttributein classFileSystemProvider
-
getFileStore
ThrowsUnsupportedOperationExceptionbecause this feature hasn't been implemented yet.- Specified by:
getFileStorein classFileSystemProvider
-
equals
-
hashCode
public int hashCode() -
toString
-
requesterPays
- Parameters:
bucketName- the name of the bucket to check- Returns:
- whether requester pays is enabled for that bucket
-
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
Returns the project that is assigned to this provider.
-