public class GoogleCloudStorageFileSystem
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.net.URI |
GCS_ROOT |
static PathCodec |
LEGACY_PATH_CODEC
A PathCodec that maintains compatibility with versions of GCS FS < 1.4.5.
|
static java.lang.String |
SCHEME |
static PathCodec |
URI_ENCODED_PATH_CODEC
A PathCodec that expects URIs to be of the form:
gs://authority/properly/encoded/path.
|
| Constructor and Description |
|---|
GoogleCloudStorageFileSystem(com.google.api.client.auth.oauth2.Credential credential,
GoogleCloudStorageFileSystemOptions options)
Constructs an instance of GoogleCloudStorageFileSystem.
|
GoogleCloudStorageFileSystem(GoogleCloudStorage gcs)
Constructs a GoogleCloudStorageFilesystem based on an already-configured underlying
GoogleCloudStorage
gcs. |
GoogleCloudStorageFileSystem(GoogleCloudStorage gcs,
GoogleCloudStorageFileSystemOptions options)
Constructs a GoogleCloudStorageFilesystem based on an already-configured underlying
GoogleCloudStorage
gcs. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Releases resources used by this instance.
|
void |
compose(java.util.List<java.net.URI> sources,
java.net.URI destination,
java.lang.String contentType)
Composes inputs into a single GCS object.
|
java.nio.channels.WritableByteChannel |
create(java.net.URI path)
Creates and opens an object for writing.
|
java.nio.channels.WritableByteChannel |
create(java.net.URI path,
CreateFileOptions options)
Creates and opens an object for writing.
|
void |
delete(java.net.URI path,
boolean recursive)
Deletes one or more items indicated by the given path.
|
boolean |
exists(java.net.URI path)
Indicates whether the given item exists.
|
FileInfo |
getFileInfo(java.net.URI path)
Gets information about the given path item.
|
java.util.List<FileInfo> |
getFileInfos(java.util.List<java.net.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.
|
static java.net.URI |
getParentPath(PathCodec pathCodec,
java.net.URI path)
Deprecated.
This static method is included as a transitional utility and the
instance method variant should be preferred.
|
java.net.URI |
getParentPath(java.net.URI path)
Gets the parent directory of the given path.
|
static java.net.URI |
getPath(java.lang.String bucketName)
Deprecated.
This method is deprecated as each instance of GCS FS can be configured
with a codec.
|
static java.net.URI |
getPath(java.lang.String bucketName,
java.lang.String objectName)
Deprecated.
This method is deprecated as each instance of GCS FS can be configured
with a codec.
|
static java.net.URI |
getPath(java.lang.String bucketName,
java.lang.String objectName,
boolean allowEmptyObjectName)
Deprecated.
This method is deprecated as each instance of GCS FS can be configured
with a codec.
|
PathCodec |
getPathCodec()
The PathCodec in use by this file system.
|
java.util.List<FileInfo> |
listAllFileInfoForPrefix(java.net.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, and there is no auto-repair
of implicit directories since we can't detect implicit directories without listing by
'delimiter'. |
GoogleCloudStorage.ListPage<FileInfo> |
listAllFileInfoForPrefixPage(java.net.URI prefix,
java.lang.String pageToken)
Equivalent to
listAllFileInfoForPrefix(java.net.URI) but returns FileInfos listed by single
request (1 page). |
java.util.List<FileInfo> |
listFileInfo(java.net.URI path,
boolean enableAutoRepair)
If the given path points to a directory then the information about its
children is returned, otherwise information about the given file is returned.
|
java.util.List<java.net.URI> |
listFileNames(FileInfo fileInfo)
If the given item is a directory then the paths of its immediate
children are returned, otherwise the path of the given item is returned.
|
java.util.List<java.net.URI> |
listFileNames(FileInfo fileInfo,
boolean recursive)
If the given item is a directory then the paths of its
children are returned, otherwise the path of the given item is returned.
|
void |
mkdir(java.net.URI path)
Creates a directory at the specified path.
|
void |
mkdirs(java.net.URI path)
Creates a directory at the specified path.
|
static CreateObjectOptions |
objectOptionsFromFileOptions(CreateFileOptions options)
Convert
CreateFileOptions to CreateObjectOptions. |
java.nio.channels.SeekableByteChannel |
open(java.net.URI path)
Opens an object for reading.
|
java.nio.channels.SeekableByteChannel |
open(java.net.URI path,
GoogleCloudStorageReadOptions readOptions)
Opens an object for reading.
|
void |
rename(java.net.URI src,
java.net.URI dst)
Renames the given item's path.
|
void |
repairDirs(java.util.List<java.net.URI> exactDirPaths)
Creates the list of directories specified in
exactDirPaths; doesn't perform validation
and doesn't create their parent dirs if their parent dirs don't already exist. |
boolean |
repairPossibleImplicitDirectory(java.net.URI path)
Checks that
path doesn't already exist as a directory object, and if so, performs an
object listing using the full path as the match prefix so that if there are any objects that
imply path is a parent directory, we will discover its existence as a returned GCS
'prefix'. |
protected void |
tryUpdateTimestampsForParentDirectories(java.util.List<java.net.URI> modifiedObjects,
java.util.List<java.net.URI> excludedParents)
For each listed modified object, attempt to update the modification time of the parent
directory.
|
protected void |
updateTimestampsForParentDirectories(java.util.List<java.net.URI> modifiedObjects,
java.util.List<java.net.URI> excludedParents)
For each listed modified object, attempt to update the modification time
of the parent directory.
|
static StorageResourceId |
validatePathAndGetId(java.net.URI uri,
boolean allowEmptyObjectNames)
Deprecated.
This method is deprecated as each instance of GCS FS can be configured
with a codec.
|
public static final java.lang.String SCHEME
public static final java.net.URI GCS_ROOT
public static final PathCodec LEGACY_PATH_CODEC
public static final PathCodec URI_ENCODED_PATH_CODEC
public GoogleCloudStorageFileSystem(com.google.api.client.auth.oauth2.Credential credential,
GoogleCloudStorageFileSystemOptions options)
throws java.io.IOException
credential - OAuth2 credential that allows access to GCS.options - Options for how this filesystem should operate and configure its
underlying storage.java.io.IOExceptionpublic GoogleCloudStorageFileSystem(GoogleCloudStorage gcs) throws java.io.IOException
gcs.java.io.IOExceptionpublic GoogleCloudStorageFileSystem(GoogleCloudStorage gcs, GoogleCloudStorageFileSystemOptions options) throws java.io.IOException
gcs. Any options pertaining to GCS creation will be ignored.java.io.IOExceptionpublic GoogleCloudStorageFileSystemOptions getOptions()
public static CreateObjectOptions objectOptionsFromFileOptions(CreateFileOptions options)
CreateFileOptions to CreateObjectOptions.public java.nio.channels.WritableByteChannel create(java.net.URI path)
throws java.io.IOException
path - Object full path of the form gs://bucket/object-path.java.io.IOExceptionpublic java.nio.channels.WritableByteChannel create(java.net.URI path,
CreateFileOptions options)
throws java.io.IOException
path - Object full path of the form gs://bucket/object-path.java.io.IOExceptionpublic java.nio.channels.SeekableByteChannel open(java.net.URI path)
throws java.io.IOException
path - Object full path of the form gs://bucket/object-path.java.io.FileNotFoundException - if the given path does not exist.java.io.IOException - if object exists but cannot be opened.public java.nio.channels.SeekableByteChannel open(java.net.URI path,
GoogleCloudStorageReadOptions readOptions)
throws java.io.IOException
path - Object full path of the form gs://bucket/object-path.readOptions - Fine-grained options for behaviors of retries, buffering, etc.java.io.FileNotFoundException - if the given path does not exist.java.io.IOException - if object exists but cannot be opened.public void delete(java.net.URI path,
boolean recursive)
throws java.io.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.java.io.FileNotFoundException - if the given path does not exist.java.io.IOExceptionpublic boolean exists(java.net.URI path)
throws java.io.IOException
path - Path of the item to check.java.io.IOExceptionpublic void repairDirs(java.util.List<java.net.URI> exactDirPaths)
throws java.io.IOException
exactDirPaths; doesn't perform validation
and doesn't create their parent dirs if their parent dirs don't already exist. Use with
caution.java.io.IOExceptionpublic void mkdirs(java.net.URI path)
throws java.io.IOException
path - Path of the directory to create.java.io.IOExceptionpublic void rename(java.net.URI src,
java.net.URI dst)
throws java.io.IOException
src - Path of the item to rename.dst - New path of the item.java.io.FileNotFoundException - if src does not exist.java.io.IOExceptionpublic void compose(java.util.List<java.net.URI> sources,
java.net.URI destination,
java.lang.String contentType)
throws java.io.IOException
sources - the list of URIs to be composeddestination - the resulting URI with composed sourcescontentType - content-type of the composed objectjava.io.IOException - if the Compose operation was unsuccessfulpublic java.util.List<java.net.URI> listFileNames(FileInfo fileInfo) throws java.io.IOException
fileInfo - FileInfo of an item.java.io.IOExceptionpublic java.util.List<java.net.URI> listFileNames(FileInfo fileInfo, boolean recursive) throws java.io.IOException
fileInfo - FileInfo of an item.recursive - If true, path of all children are returned;
else, only immediate children are returned.java.io.IOExceptionpublic boolean repairPossibleImplicitDirectory(java.net.URI path)
throws java.io.IOException
path doesn't already exist as a directory object, and if so, performs an
object listing using the full path as the match prefix so that if there are any objects that
imply path is a parent directory, we will discover its existence as a returned GCS
'prefix'. In such a case, the directory object will be explicitly created.
Helper for repairing implicit directories, taking a previously obtained FileInfo and returning a re-fetched FileInfo after attempting the repair. The returned FileInfo may still report !exists() if the repair failed.
java.io.IOExceptionpublic java.util.List<FileInfo> listAllFileInfoForPrefix(java.net.URI prefix) throws java.io.IOException
prefix, except that prefix doesn't have to
represent an actual object but can just be a partial prefix string, and there is no auto-repair
of implicit directories since we can't detect implicit directories without listing by
'delimiter'. 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.java.io.IOExceptionpublic GoogleCloudStorage.ListPage<FileInfo> listAllFileInfoForPrefixPage(java.net.URI prefix, java.lang.String pageToken) throws java.io.IOException
listAllFileInfoForPrefix(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 listjava.io.IOExceptionpublic java.util.List<FileInfo> listFileInfo(java.net.URI path, boolean enableAutoRepair) throws java.io.IOException
listFileNames(FileInfo) if you only need
names of children and no other attributes.path - Given path.enableAutoRepair - if true, attempt to repair implicit directories when detected.java.io.FileNotFoundException - if the given path does not exist.java.io.IOExceptionpublic FileInfo getFileInfo(java.net.URI path) throws java.io.IOException
path - The path we want information about.java.io.IOExceptionpublic java.util.List<FileInfo> getFileInfos(java.util.List<java.net.URI> paths) throws java.io.IOException
paths - List of paths.java.io.IOExceptionpublic void close()
public void mkdir(java.net.URI path)
throws java.io.IOException
java.io.IOExceptionprotected void updateTimestampsForParentDirectories(java.util.List<java.net.URI> modifiedObjects,
java.util.List<java.net.URI> excludedParents)
throws java.io.IOException
modifiedObjects - The objects that have been modifiedexcludedParents - A list of parent directories that we shouldn't attempt to update.java.io.IOExceptionprotected void tryUpdateTimestampsForParentDirectories(java.util.List<java.net.URI> modifiedObjects,
java.util.List<java.net.URI> excludedParents)
This method will log & swallow exceptions thrown by the GCSIO layer.
modifiedObjects - The objects that have been modifiedexcludedParents - A list of parent directories that we shouldn't attempt to update.public java.net.URI getParentPath(java.net.URI path)
path - Path to convert.public GoogleCloudStorage getGcs()
public PathCodec getPathCodec()
@Deprecated public static StorageResourceId validatePathAndGetId(java.net.URI uri, boolean allowEmptyObjectNames)
@Deprecated
public static java.net.URI getPath(java.lang.String bucketName,
java.lang.String objectName,
boolean allowEmptyObjectName)
@Deprecated public static java.net.URI getPath(java.lang.String bucketName)
@Deprecated
public static java.net.URI getPath(java.lang.String bucketName,
java.lang.String objectName)
@Deprecated public static java.net.URI getParentPath(PathCodec pathCodec, java.net.URI path)
path - Path to convert.Copyright © 2019. All rights reserved.