@Singleton @ThreadSafe @AutoService(value=java.nio.file.spi.FileSystemProvider.class) public final class CloudStorageFileSystemProvider extends FileSystemProvider
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 and Description |
|---|
CloudStorageFileSystemProvider()
Default constructor which should only be called by Java SPI.
|
| Modifier and Type | Method and 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> |
getFileAttributeView(Path path,
Class<V> type,
LinkOption... options) |
FileStore |
getFileStore(Path path)
Throws
UnsupportedOperationException 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 returns
false, 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> |
readAttributes(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)
Throws
UnsupportedOperationException 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(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.
|
createLink, createSymbolicLink, installedProviders, newAsynchronousFileChannel, newFileSystem, newOutputStream, readSymbolicLinkpublic CloudStorageFileSystemProvider()
public static void setStorageOptions(@Nullable StorageOptions newStorageOptions)
Instead of calling this, when possible use CloudStorageFileSystem.forBucket and pass StorageOptions as an argument.
public static void setDefaultCloudStorageConfiguration(@Nullable CloudStorageConfiguration newDefault)
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.
newDefault - new default CloudStorageConfigurationpublic String getScheme()
getScheme in class FileSystemProviderpublic CloudStorageFileSystem getFileSystem(URI uri)
gs://bucket.getFileSystem in class FileSystemProviderpublic CloudStorageFileSystem newFileSystem(URI uri, Map<String,?> env)
gs://bucket. The URI can
include a path component (that will be ignored).newFileSystem in class FileSystemProvideruri - bucket and current working directory, e.g. gs://bucketenv - map of configuration options, whose keys correspond to the method names of CloudStorageConfiguration.Builder. However you are not allowed to set the working
directory, as that should be provided in the uriIllegalArgumentException - if uri specifies a port, user, query, or fragment, or
if scheme is not public CloudStoragePath getPath(URI uri)
getPath in class FileSystemProviderpublic CloudStoragePath getPath(String uriInStringForm)
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
newByteChannel in class FileSystemProviderpath: - 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)IOExceptionpublic FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
FileChannel that is returned will only allow
reads or writes depending on the OpenOptions that are specified. If any of the
following have been specified, the FileChannel will be write-only: StandardOpenOption.CREATE
StandardOpenOption.CREATE
StandardOpenOption.CREATE_NEW
StandardOpenOption.WRITE
StandardOpenOption.TRUNCATE_EXISTING
FileChannel will be read-only.newFileChannel in class FileSystemProviderpath - The path to the file to open or createoptions - The options specifying how the file should be opened, and whether the FileChannel should be read-only or write-only.attrs - (not supported, the values will be ignored)IOExceptionpublic InputStream newInputStream(Path path, OpenOption... options) throws IOException
newInputStream in class FileSystemProviderIOExceptionpublic boolean deleteIfExists(Path path) throws IOException
deleteIfExists in class FileSystemProviderIOExceptionpublic void delete(Path path) throws IOException
delete in class FileSystemProviderIOExceptionpublic void move(Path source, Path target, CopyOption... options) throws IOException
move in class FileSystemProviderIOExceptionpublic void copy(Path source, Path target, CopyOption... options) throws IOException
copy in class FileSystemProviderIOExceptionpublic boolean isSameFile(Path path, Path path2)
isSameFile in class FileSystemProviderpublic boolean isHidden(Path path)
false, because Google Cloud Storage doesn't support hidden files.isHidden in class FileSystemProviderpublic void checkAccess(Path path, AccessMode... modes) throws IOException
checkAccess in class FileSystemProviderIOExceptionpublic <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException
readAttributes in class FileSystemProviderIOExceptionpublic Map<String,Object> readAttributes(Path path, String attributes, LinkOption... options)
readAttributes in class FileSystemProviderpublic <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options)
getFileAttributeView in class FileSystemProviderpublic void createDirectory(Path dir, FileAttribute<?>... attrs)
createDirectory in class FileSystemProviderpublic DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)
newDirectoryStream in class FileSystemProviderpublic void setAttribute(Path path, String attribute, Object value, LinkOption... options)
UnsupportedOperationException because Cloud Storage objects are immutable.setAttribute in class FileSystemProviderpublic FileStore getFileStore(Path path)
UnsupportedOperationException because this feature hasn't been implemented yet.getFileStore in class FileSystemProviderpublic boolean requesterPays(String bucketName)
bucketName - the name of the bucket to checkpublic CloudStorageFileSystemProvider withNoUserProject()
Perhaps you want to call this is you realize you'll be working on a bucket that is not requester-pays.
public String getProject()
Copyright © 2019 Google LLC. All rights reserved.