Class CloudStorageFileSystemProvider (0.127.22)

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.

Inheritance

Object > FileSystemProvider > CloudStorageFileSystemProvider

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.

Parameter
Name Description
newDefault CloudStorageConfiguration

new default CloudStorageConfiguration

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()

Default constructor which should only be called by Java SPI. See Also: CloudStorageFileSystem#forBucket(String), java.nio.file.FileSystems#getFileSystem(URI)

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[]
Returns
Type Description
A
Overrides
Exceptions
Type Description
IOException

<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[]
Returns
Type Description
V
Overrides

checkAccess(Path path, AccessMode[] modes)

public void checkAccess(Path path, AccessMode[] modes)
Parameters
Name Description
path Path
modes java.nio.file.AccessMode[]
Overrides
Exceptions
Type Description
IOException

copy(Path source, Path target, CopyOption[] options)

public void copy(Path source, Path target, CopyOption[] options)
Parameters
Name Description
source Path
target Path
options CopyOption[]
Overrides
Exceptions
Type Description
IOException

createDirectory(Path dir, FileAttribute<?>[] attrs)

public void createDirectory(Path dir, FileAttribute<?>[] attrs)

Does nothing since Google Cloud Storage uses fake directories.

Parameters
Name Description
dir Path
attrs FileAttribute<?>[]
Overrides

delete(Path path)

public void delete(Path path)
Parameter
Name Description
path Path
Overrides
Exceptions
Type Description
IOException

deleteIfExists(Path path)

public boolean deleteIfExists(Path path)
Parameter
Name Description
path Path
Returns
Type Description
boolean
Overrides
Exceptions
Type Description
IOException

equals(Object other)

public boolean equals(Object other)
Parameter
Name Description
other Object
Returns
Type Description
boolean
Overrides

getFileStore(Path path)

public FileStore getFileStore(Path path)

Throws UnsupportedOperationException because this feature hasn't been implemented yet.

Parameter
Name Description
path Path
Returns
Type Description
FileStore
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
Returns
Type Description
CloudStorageFileSystem
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
Returns
Type Description
CloudStoragePath

getPath(URI uri)

public CloudStoragePath getPath(URI uri)
Parameter
Name Description
uri URI
Returns
Type Description
CloudStoragePath
Overrides

getProject()

public String getProject()

Returns the project that is assigned to this provider.

Returns
Type Description
String

getScheme()

public String getScheme()
Returns
Type Description
String
Overrides

hashCode()

public int 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
Returns
Type Description
boolean
Overrides

isSameFile(Path path, Path path2)

public boolean isSameFile(Path path, Path path2)
Parameters
Name Description
path Path
path2 Path
Returns
Type Description
boolean
Overrides

move(Path source, Path target, CopyOption[] options)

public void move(Path source, Path target, CopyOption[] options)
Parameters
Name Description
source Path
target Path
options CopyOption[]
Overrides
Exceptions
Type Description
IOException

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)

Returns
Type Description
SeekableByteChannel
Overrides
Exceptions
Type Description
IOException

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>
Returns
Type Description
DirectoryStream<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)

Returns
Type Description
FileChannel
Overrides
Exceptions
Type Description
IOException

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

Returns
Type Description
CloudStorageFileSystem
Overrides

newInputStream(Path path, OpenOption[] options)

public InputStream newInputStream(Path path, OpenOption[] options)
Parameters
Name Description
path Path
options OpenOption[]
Returns
Type Description
InputStream
Overrides
Exceptions
Type Description
IOException

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[]
Returns
Type Description
Map<String,Object>
Overrides
Exceptions
Type Description
IOException

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)

Throws UnsupportedOperationException because Cloud Storage objects are immutable.

Parameters
Name Description
path Path
attribute String
value Object
options java.nio.file.LinkOption[]
Overrides

toString()

public String toString()
Returns
Type Description
String
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.

Returns
Type Description
CloudStorageFileSystemProvider