public class GoogleCloudStorageFileSystem extends Object
| Modifier and Type | Field and Description |
|---|---|
static URI |
GCS_ROOT |
static PathCodec |
LEGACY_PATH_CODEC
A PathCodec that maintains compatibility with versions of GCS FS < 1.4.5.
|
static org.slf4j.Logger |
LOG |
static 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(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 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.
|
GoogleCloudStorageFileSystemOptions |
getOptions()
Retrieve the options that were used to create this
GoogleCloudStorageFileSystem.
|
static URI |
getParentPath(PathCodec pathCodec,
URI path)
Deprecated.
This static method is included as a transitional utility and the
instance method variant should be preferred.
|
URI |
getParentPath(URI path)
Gets the parent directory of the given path.
|
static URI |
getPath(String bucketName)
Deprecated.
This method is deprecated as each instance of GCS FS can be configured
with a codec.
|
static URI |
getPath(String bucketName,
String objectName)
Deprecated.
This method is deprecated as each instance of GCS FS can be configured
with a codec.
|
static URI |
getPath(String bucketName,
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.
|
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. |
SeekableByteChannel |
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
that 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 uri,
boolean allowEmptyObjectNames)
Deprecated.
This method is deprecated as each instance of GCS FS can be configured
with a codec.
|
public static final String SCHEME
public static final URI GCS_ROOT
public static final org.slf4j.Logger LOG
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 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 GoogleCloudStorageFileSystemOptions getOptions()
public 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 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 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 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<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
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.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 URI getParentPath(URI path)
path - Path to convert.public PathCodec getPathCodec()
@Deprecated public static StorageResourceId validatePathAndGetId(URI uri, boolean allowEmptyObjectNames)
@Deprecated public static URI getPath(String bucketName, String objectName, boolean allowEmptyObjectName)
@Deprecated public static URI getPath(String bucketName)
@Deprecated public static URI getPath(String bucketName, String objectName)
@Deprecated public static URI getParentPath(PathCodec pathCodec, URI path)
path - Path to convert.Copyright © 2016. All rights reserved.