public class GoogleCloudStorageFileSystem extends Object
| Modifier and Type | Field and Description |
|---|---|
static URI |
GCS_ROOT |
static LogUtil |
log |
static String |
SCHEME |
| 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.
|
WritableByteChannel |
create(URI path)
Creates and opens an object for writing.
|
WritableByteChannel |
create(URI path,
CreateFileOptions options)
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.
|
static URI |
getParentPath(URI path)
Gets the parent directory of the given path.
|
static URI |
getPath(String bucketName)
Constructs and returns full path for the given bucket name.
|
static URI |
getPath(String bucketName,
String objectName)
Constructs and returns full path for the given object name.
|
static URI |
getPath(String bucketName,
String objectName,
boolean allowEmptyObjectName)
Constructs and returns full path for the given object name.
|
List<FileInfo> |
listAllFileInfoForPrefix(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'. |
List<FileInfo> |
listFileInfo(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.
|
List<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.
|
List<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(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. |
SeekableReadableByteChannel |
open(URI path)
Opens an object for reading.
|
void |
rename(URI src,
URI dst)
Renames the given item's path.
|
void |
repairDirs(List<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(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
which imply path is a parent directory, we will discover its existence as a returned
GCS 'prefix'. |
protected void |
tryUpdateTimestampsForParentDirectories(List<URI> modifiedObjects,
List<URI> excludedParents)
For each listed modified object, attempt to update the modification time
of the parent directory.
|
protected void |
updateTimestampsForParentDirectories(List<URI> modifiedObjects,
List<URI> excludedParents)
For each listed modified object, attempt to update the modification time
of the parent directory.
|
static StorageResourceId |
validatePathAndGetId(URI path,
boolean allowEmptyObjectName)
Validates the given URI and if valid, returns the associated StorageResourceId.
|
public static final String SCHEME
public static final URI GCS_ROOT
public static LogUtil log
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(GoogleCloudStorage gcs) throws IOException
gcs.IOExceptionpublic GoogleCloudStorageFileSystem(GoogleCloudStorage gcs, GoogleCloudStorageFileSystemOptions options) throws IOException
gcs. Any options pertaining to GCS creation will be ignored.IOExceptionpublic WritableByteChannel create(URI path) throws IOException
path - Object full path of the form gs://bucket/object-path.IOExceptionpublic static CreateObjectOptions objectOptionsFromFileOptions(CreateFileOptions options)
CreateFileOptions to CreateObjectOptions.public WritableByteChannel create(URI path, CreateFileOptions options) throws IOException
path - Object full path of the form gs://bucket/object-path.IOExceptionpublic SeekableReadableByteChannel 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 void delete(URI path, boolean recursive) throws IOException
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 repairDirs(List<URI> exactDirPaths) throws IOException
exactDirPaths; doesn't perform validation
and doesn't create their parent dirs if their parent dirs don't already exist. Use with
caution.IOExceptionpublic void mkdirs(URI path) throws IOException
path - Path of the directory to create.IOExceptionpublic void rename(URI src, URI dst) throws IOException
src - Path of the item to rename.dst - New path of the item.FileNotFoundException - if src does not exist.IOExceptionpublic List<URI> listFileNames(FileInfo fileInfo) throws IOException
fileInfo - FileInfo of an item.IOExceptionpublic List<URI> listFileNames(FileInfo fileInfo, boolean recursive) throws IOException
fileInfo - FileInfo of an item.recursive - If true, path of all children are returned;
else, only immediate children are returned.IOExceptionpublic boolean repairPossibleImplicitDirectory(URI path) throws 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
which 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.IOExceptionpublic List<FileInfo> listAllFileInfoForPrefix(URI prefix) throws 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.IOExceptionpublic List<FileInfo> listFileInfo(URI path, boolean enableAutoRepair) throws 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.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
IOExceptionprotected void updateTimestampsForParentDirectories(List<URI> modifiedObjects, List<URI> excludedParents) throws IOException
modifiedObjects - The objects that have been modifiedexcludedParents - A list of parent directories that we shouldn't attempt to update.IOExceptionprotected void tryUpdateTimestampsForParentDirectories(List<URI> modifiedObjects, List<URI> excludedParents)
modifiedObjects - The objects that have been modifiedexcludedParents - A list of parent directories that we shouldn't attempt to update.public static StorageResourceId validatePathAndGetId(URI path, boolean allowEmptyObjectName)
path - The GCS URI to validate.allowEmptyObjectName - If true, a missing object name is not considered invalid.public static URI getPath(String bucketName)
public static URI getPath(String bucketName, String objectName)
public static URI getPath(String bucketName, String objectName, boolean allowEmptyObjectName)
Copyright © 2015. All rights reserved.