public class GoogleCloudStorageFileSystem extends Object
All file system aspects (eg, path) are encapsulated in this class, they are not exposed to the underlying layer. That is, all interactions with the underlying layer are strictly in terms of buckets and objects.
| Modifier and Type | Field and Description |
|---|---|
static ListFileOptions |
DELETE_RENAME_LIST_OPTIONS |
static URI |
GCS_ROOT |
static String |
SCHEME |
| Constructor and Description |
|---|
GoogleCloudStorageFileSystem(CheckedFunction<GoogleCloudStorageOptions,GoogleCloudStorage,IOException> gcsFn,
GoogleCloudStorageFileSystemOptions options)
Constructs a GoogleCloudStorageFilesystem based on an already-configured underlying
GoogleCloudStorage
gcs. |
GoogleCloudStorageFileSystem(com.google.api.client.auth.oauth2.Credential credential,
Function<List<AccessBoundary>,String> downscopedAccessTokenFn,
GoogleCloudStorageFileSystemOptions options)
Constructs an instance of GoogleCloudStorageFileSystem.
|
GoogleCloudStorageFileSystem(com.google.api.client.auth.oauth2.Credential credential,
GoogleCloudStorageFileSystemOptions options)
Constructs an instance of GoogleCloudStorageFileSystem.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Releases resources used by this instance.
|
void |
compose(List<URI> sources,
URI destination,
String contentType)
Composes inputs into a single GCS object.
|
WritableByteChannel |
create(URI path)
Creates and opens an object for writing.
|
WritableByteChannel |
create(URI path,
CreateFileOptions createOptions)
Creates and opens an object for writing.
|
void |
delete(URI path,
boolean recursive)
Deletes one or more items indicated by the given path.
|
boolean |
exists(URI path)
Indicates whether the given item exists.
|
FileInfo |
getFileInfo(URI path)
Gets information about the given path item.
|
List<FileInfo> |
getFileInfos(List<URI> paths)
Gets information about each path in the given list; more efficient than calling getFileInfo()
on each path individually in a loop.
|
GoogleCloudStorage |
getGcs()
Retrieve our internal gcs.
|
GoogleCloudStorageFileSystemOptions |
getOptions()
Retrieve the options that were used to create this GoogleCloudStorageFileSystem.
|
List<FileInfo> |
listFileInfo(URI path)
If the given path points to a directory then the information about its children is returned,
otherwise information about the given file is returned.
|
List<FileInfo> |
listFileInfo(URI path,
ListFileOptions listOptions)
If the given path points to a directory then the information about its children is returned,
otherwise information about the given file is returned.
|
List<FileInfo> |
listFileInfoForPrefix(URI prefix)
Equivalent to a recursive listing of
prefix, except that prefix doesn't have to
represent an actual object but can just be a partial prefix string. |
List<FileInfo> |
listFileInfoForPrefix(URI prefix,
ListFileOptions listOptions)
Equivalent to a recursive listing of
prefix, except that prefix doesn't have to
represent an actual object but can just be a partial prefix string. |
GoogleCloudStorage.ListPage<FileInfo> |
listFileInfoForPrefixPage(URI prefix,
ListFileOptions listOptions,
String pageToken)
Equivalent to
listFileInfoForPrefix(java.net.URI) but returns FileInfos listed by single
request (1 page). |
GoogleCloudStorage.ListPage<FileInfo> |
listFileInfoForPrefixPage(URI prefix,
String pageToken)
Equivalent to
listFileInfoForPrefix(java.net.URI) but returns FileInfos listed by single
request (1 page). |
void |
mkdir(URI path)
Creates a directory at the specified path.
|
void |
mkdirs(URI path)
Creates a directory at the specified path.
|
static CreateObjectOptions |
objectOptionsFromFileOptions(CreateFileOptions options)
Convert
CreateFileOptions to CreateObjectOptions. |
SeekableByteChannel |
open(URI path)
Opens an object for reading.
|
SeekableByteChannel |
open(URI path,
GoogleCloudStorageReadOptions readOptions)
Opens an object for reading.
|
void |
rename(URI src,
URI dst)
Renames the given item's path.
|
public static final String SCHEME
public static final URI GCS_ROOT
public static final ListFileOptions DELETE_RENAME_LIST_OPTIONS
public GoogleCloudStorageFileSystem(com.google.api.client.auth.oauth2.Credential credential,
GoogleCloudStorageFileSystemOptions options)
throws IOException
credential - OAuth2 credential that allows access to GCS.options - Options for how this filesystem should operate and configure its underlying
storage.IOExceptionpublic GoogleCloudStorageFileSystem(com.google.api.client.auth.oauth2.Credential credential,
Function<List<AccessBoundary>,String> downscopedAccessTokenFn,
GoogleCloudStorageFileSystemOptions options)
throws IOException
credential - OAuth2 credential that allows access to GCS.downscopedAccessTokenFn - Function that generates downscoped access token.options - Options for how this filesystem should operate and configure its underlying
storage.IOExceptionpublic GoogleCloudStorageFileSystem(CheckedFunction<GoogleCloudStorageOptions,GoogleCloudStorage,IOException> gcsFn, GoogleCloudStorageFileSystemOptions options) throws IOException
gcs. Any options pertaining to GCS creation will be ignored.IOExceptionpublic GoogleCloudStorageFileSystemOptions getOptions()
public static CreateObjectOptions objectOptionsFromFileOptions(CreateFileOptions options)
CreateFileOptions to CreateObjectOptions.public WritableByteChannel create(URI path) throws IOException
path - Object full path of the form gs://bucket/object-path.IOExceptionpublic WritableByteChannel create(URI path, CreateFileOptions createOptions) throws IOException
path - Object full path of the form gs://bucket/object-path.IOExceptionpublic SeekableByteChannel open(URI path) throws IOException
path - Object full path of the form gs://bucket/object-path.FileNotFoundException - if the given path does not exist.IOException - if object exists but cannot be opened.public SeekableByteChannel open(URI path, GoogleCloudStorageReadOptions readOptions) throws IOException
path - Object full path of the form gs://bucket/object-path.readOptions - Fine-grained options for behaviors of retries, buffering, etc.FileNotFoundException - if the given path does not exist.IOException - if object exists but cannot be opened.public void delete(URI path, boolean recursive) throws IOException
If path points to a directory:
The recursive parameter is ignored for a file.
path - Path of the item to delete.recursive - If true, all sub-items are also deleted.FileNotFoundException - if the given path does not exist.IOExceptionpublic boolean exists(URI path) throws IOException
path - Path of the item to check.IOExceptionpublic void mkdirs(URI path) throws IOException
path - Path of the directory to create.IOExceptionpublic void rename(URI src, URI dst) throws IOException
The operation is disallowed if any of the following is true:
Otherwise, the expected behavior is as follows:
Note: This function is very expensive to call for directories that have many sub-items.
src - Path of the item to rename.dst - New path of the item.FileNotFoundException - if src does not exist.IOExceptionpublic void compose(List<URI> sources, URI destination, String contentType) throws IOException
sources - the list of URIs to be composeddestination - the resulting URI with composed sourcescontentType - content-type of the composed objectIOException - if the Compose operation was unsuccessfulpublic List<FileInfo> listFileInfoForPrefix(URI prefix) throws IOException
prefix, except that prefix doesn't have to
represent an actual object but can just be a partial prefix string. The 'authority' component
of the prefix must be the complete authority, however; we can only list prefixes
of objects, not buckets.prefix - the prefix to use to list all matching objects.IOExceptionpublic List<FileInfo> listFileInfoForPrefix(URI prefix, ListFileOptions listOptions) throws IOException
prefix, except that prefix doesn't have to
represent an actual object but can just be a partial prefix string. The 'authority' component
of the prefix must be the complete authority, however; we can only list prefixes
of objects, not buckets.prefix - the prefix to use to list all matching objects.IOExceptionpublic GoogleCloudStorage.ListPage<FileInfo> listFileInfoForPrefixPage(URI prefix, String pageToken) throws IOException
listFileInfoForPrefix(java.net.URI) but returns FileInfos listed by single
request (1 page).prefix - the prefix to use to list all matching objects.pageToken - the page token to listIOExceptionpublic GoogleCloudStorage.ListPage<FileInfo> listFileInfoForPrefixPage(URI prefix, ListFileOptions listOptions, String pageToken) throws IOException
listFileInfoForPrefix(java.net.URI) but returns FileInfos listed by single
request (1 page).prefix - the prefix to use to list all matching objects.pageToken - the page token to listIOExceptionpublic List<FileInfo> listFileInfo(URI path) throws IOException
path - Given path.FileNotFoundException - if the given path does not exist.IOExceptionpublic List<FileInfo> listFileInfo(URI path, ListFileOptions listOptions) throws IOException
path - Given path.FileNotFoundException - if the given path does not exist.IOExceptionpublic FileInfo getFileInfo(URI path) throws IOException
path - The path we want information about.IOExceptionpublic List<FileInfo> getFileInfos(List<URI> paths) throws IOException
paths - List of paths.IOExceptionpublic void close()
public void mkdir(URI path) throws IOException
There are two conventions for using objects as directories in GCS. 1. An object of zero size with name ending in / 2. An object of zero size with name ending in _$folder$
#1 is the recommended convention by the GCS team. We use it when creating a directory.
However, some old tools still use #2. We will decide based on customer use cases whether to support #2 as well. For now, we only support #1.
Note that a bucket is always considered a directory. Doesn't create parent directories; normal use cases should only call mkdirs().
IOExceptionpublic GoogleCloudStorage getGcs()
Copyright © 2022. All rights reserved.