Class CloudStorageFileSystemProvider (0.124.3)

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
NameDescription
newDefaultCloudStorageConfiguration

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
NameDescription
newStorageOptionscom.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
NameDescription
pathPath
typeClass<A>
optionsjava.nio.file.LinkOption[]
Returns
TypeDescription
A
Overrides Exceptions
TypeDescription
IOException

<V>getFileAttributeView(Path path, Class<V> type, LinkOption[] options)

public V <V>getFileAttributeView(Path path, Class<V> type, LinkOption[] options)
Parameters
NameDescription
pathPath
typeClass<V>
optionsjava.nio.file.LinkOption[]
Returns
TypeDescription
V
Overrides

checkAccess(Path path, AccessMode[] modes)

public void checkAccess(Path path, AccessMode[] modes)
Parameters
NameDescription
pathPath
modesjava.nio.file.AccessMode[]
Overrides Exceptions
TypeDescription
IOException

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

public void copy(Path source, Path target, CopyOption[] options)
Parameters
NameDescription
sourcePath
targetPath
optionsCopyOption[]
Overrides Exceptions
TypeDescription
IOException

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

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

Does nothing since Google Cloud Storage uses fake directories.

Parameters
NameDescription
dirPath
attrsFileAttribute<?>[]
Overrides

delete(Path path)

public void delete(Path path)
Parameter
NameDescription
pathPath
Overrides Exceptions
TypeDescription
IOException

deleteIfExists(Path path)

public boolean deleteIfExists(Path path)
Parameter
NameDescription
pathPath
Returns
TypeDescription
boolean
Overrides Exceptions
TypeDescription
IOException

equals(Object other)

public boolean equals(Object other)
Parameter
NameDescription
otherObject
Returns
TypeDescription
boolean
Overrides

getFileStore(Path path)

public FileStore getFileStore(Path path)

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

Parameter
NameDescription
pathPath
Returns
TypeDescription
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
NameDescription
uriURI
Returns
TypeDescription
CloudStorageFileSystem
Overrides

getPath(String uriInStringForm)

public CloudStoragePath getPath(String uriInStringForm)

Convenience method: replaces spaces with "%20", builds a URI, and calls getPath(uri).

Parameter
NameDescription
uriInStringFormString
Returns
TypeDescription
CloudStoragePath

getPath(URI uri)

public CloudStoragePath getPath(URI uri)
Parameter
NameDescription
uriURI
Returns
TypeDescription
CloudStoragePath
Overrides

getProject()

public String getProject()

Returns the project that is assigned to this provider.

Returns
TypeDescription
String

getScheme()

public String getScheme()
Returns
TypeDescription
String
Overrides

hashCode()

public int hashCode()
Returns
TypeDescription
int
Overrides

isHidden(Path path)

public boolean isHidden(Path path)

Always returns false, because Google Cloud Storage doesn't support hidden files.

Parameter
NameDescription
pathPath
Returns
TypeDescription
boolean
Overrides

isSameFile(Path path, Path path2)

public boolean isSameFile(Path path, Path path2)
Parameters
NameDescription
pathPath
path2Path
Returns
TypeDescription
boolean
Overrides

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

public void move(Path source, Path target, CopyOption[] options)
Parameters
NameDescription
sourcePath
targetPath
optionsCopyOption[]
Overrides Exceptions
TypeDescription
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
NameDescription
pathPath

: the path to the file to open or create

optionsSet<? extends java.nio.file.OpenOption>

: options specifying how the file is opened, e.g. StandardOpenOption.WRITE or BlobSourceOption.userProject

attrsFileAttribute<?>[]

: (not supported, values will be ignored)

Returns
TypeDescription
SeekableByteChannel
Overrides Exceptions
TypeDescription
IOException

newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)

public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)
Parameters
NameDescription
dirPath
filterFilter<? super java.nio.file.Path>
Returns
TypeDescription
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
NameDescription
pathPath

The path to the file to open or create

optionsSet<? 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.

attrsFileAttribute<?>[]

(not supported, the values will be ignored)

Returns
TypeDescription
FileChannel
Overrides Exceptions
TypeDescription
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
NameDescription
uriURI

bucket and current working directory, e.g. gs://bucket

envMap<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
TypeDescription
CloudStorageFileSystem
Overrides

newInputStream(Path path, OpenOption[] options)

public InputStream newInputStream(Path path, OpenOption[] options)
Parameters
NameDescription
pathPath
optionsOpenOption[]
Returns
TypeDescription
InputStream
Overrides Exceptions
TypeDescription
IOException

readAttributes(Path path, String attributes, LinkOption[] options)

public Map<String,Object> readAttributes(Path path, String attributes, LinkOption[] options)
Parameters
NameDescription
pathPath
attributesString
optionsjava.nio.file.LinkOption[]
Returns
TypeDescription
Map<String,Object>
Overrides

requesterPays(String bucketName)

public boolean requesterPays(String bucketName)
Parameter
NameDescription
bucketNameString

the name of the bucket to check

Returns
TypeDescription
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
NameDescription
pathPath
attributeString
valueObject
optionsjava.nio.file.LinkOption[]
Overrides

toString()

public String toString()
Returns
TypeDescription
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
TypeDescription
CloudStorageFileSystemProvider