public final class CloudStorageFileSystemProvider extends FileSystemProvider
Google Cloud Storage 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. java.nio.file.Files. However
the javadocs in this class serve as useful documentation for the behavior of the Google Cloud
Storage NIO library.
Static Methods
setDefaultCloudStorageConfiguration(CloudStorageConfiguration newDefault)
public static void setDefaultCloudStorageConfiguration(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.
setStorageOptions(StorageOptions newStorageOptions)
public static void setStorageOptions(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.
Parameter |
---|
Name | Description |
newStorageOptions | com.google.cloud.storage.StorageOptions
|
Constructors
CloudStorageFileSystemProvider()
public CloudStorageFileSystemProvider()
Methods
<A>readAttributes(Path path, Class<A> type, LinkOption[] options)
public A <A>readAttributes(Path path, Class<A> type, LinkOption[] options)
Parameters |
---|
Name | Description |
path | Path
|
type | Class<A>
|
options | java.nio.file.LinkOption[]
|
Overrides
<V>getFileAttributeView(Path path, Class<V> type, LinkOption[] options)
public V <V>getFileAttributeView(Path path, Class<V> type, LinkOption[] options)
Parameters |
---|
Name | Description |
path | Path
|
type | Class<V>
|
options | java.nio.file.LinkOption[]
|
Overrides
checkAccess(Path path, AccessMode[] modes)
public void checkAccess(Path path, AccessMode[] modes)
Parameters |
---|
Name | Description |
path | Path
|
modes | java.nio.file.AccessMode[]
|
Overrides
copy(Path source, Path target, CopyOption[] options)
public void copy(Path source, Path target, CopyOption[] options)
Overrides
createDirectory(Path dir, FileAttribute<?>[] attrs)
public void createDirectory(Path dir, FileAttribute<?>[] attrs)
Does nothing since Google Cloud Storage uses fake directories.
Overrides
delete(Path path)
public void delete(Path path)
Parameter |
---|
Name | Description |
path | Path
|
Overrides
deleteIfExists(Path path)
public boolean deleteIfExists(Path path)
Parameter |
---|
Name | Description |
path | Path
|
Overrides
equals(Object other)
public boolean equals(Object other)
Parameter |
---|
Name | Description |
other | Object
|
Overrides
getFileStore(Path path)
public FileStore getFileStore(Path path)
Parameter |
---|
Name | Description |
path | Path
|
Overrides
getFileSystem(URI uri)
public CloudStorageFileSystem getFileSystem(URI uri)
Returns Cloud Storage file system, provided a URI with no path, e.g. gs://bucket
.
Parameter |
---|
Name | Description |
uri | URI
|
Overrides
getPath(String uriInStringForm)
public CloudStoragePath getPath(String uriInStringForm)
Convenience method: replaces spaces with "%20", builds a URI, and calls getPath(uri).
Parameter |
---|
Name | Description |
uriInStringForm | String
|
getPath(URI uri)
public CloudStoragePath getPath(URI uri)
Parameter |
---|
Name | Description |
uri | URI
|
Overrides
getProject()
public String getProject()
Returns the project that is assigned to this provider.
getScheme()
public String getScheme()
Overrides
hashCode()
Returns |
---|
Type | Description |
int | |
Overrides
isHidden(Path path)
public boolean isHidden(Path path)
Always returns false
, because Google Cloud Storage doesn't support hidden files.
Parameter |
---|
Name | Description |
path | Path
|
Overrides
isSameFile(Path path, Path path2)
public boolean isSameFile(Path path, Path path2)
Parameters |
---|
Name | Description |
path | Path
|
path2 | Path
|
Overrides
move(Path source, Path target, CopyOption[] options)
public void move(Path source, Path target, CopyOption[] options)
Overrides
newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>[] attrs)
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>[] attrs)
Open a file for reading or writing. To read receiver-pays buckets, specify the
BlobSourceOption.userProject option.
Parameters |
---|
Name | Description |
path | Path
: the path to the file to open or create
|
options | Set<? extends java.nio.file.OpenOption>
: options specifying how the file is opened, e.g. StandardOpenOption.WRITE or
BlobSourceOption.userProject
|
attrs | FileAttribute<?>[]
: (not supported, values will be ignored)
|
Overrides
newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)
Parameters |
---|
Name | Description |
dir | Path
|
filter | Filter<? super java.nio.file.Path>
|
Overrides
newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>[] attrs)
public FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>[] attrs)
Open a file for reading OR writing. The 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
In all other cases the FileChannel will be read-only.
Parameters |
---|
Name | Description |
path | Path
The path to the file to open or create
|
options | Set<? extends java.nio.file.OpenOption>
The options specifying how the file should be opened, and whether the FileChannel should be read-only or write-only.
|
attrs | FileAttribute<?>[]
(not supported, the values will be ignored)
|
Overrides
newFileSystem(URI uri, Map<String,?> env)
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).
Parameters |
---|
Name | Description |
uri | URI
bucket and current working directory, e.g. gs://bucket
|
env | Map<String,?>
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 uri
|
Overrides
public InputStream newInputStream(Path path, OpenOption[] options)
Overrides
readAttributes(Path path, String attributes, LinkOption[] options)
public Map<String,Object> readAttributes(Path path, String attributes, LinkOption[] options)
Parameters |
---|
Name | Description |
path | Path
|
attributes | String
|
options | java.nio.file.LinkOption[]
|
Overrides
requesterPays(String bucketName)
public boolean requesterPays(String bucketName)
Parameter |
---|
Name | Description |
bucketName | String
the name of the bucket to check
|
Returns |
---|
Type | Description |
boolean | whether requester pays is enabled for that bucket
|
setAttribute(Path path, String attribute, Object value, LinkOption[] options)
public void setAttribute(Path path, String attribute, Object value, LinkOption[] options)
Parameters |
---|
Name | Description |
path | Path
|
attribute | String
|
value | Object
|
options | java.nio.file.LinkOption[]
|
Overrides
toString()
Overrides
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.