Class GoogleCloudStorageFileSystemImpl
- java.lang.Object
-
- com.google.cloud.hadoop.gcsio.GoogleCloudStorageFileSystemImpl
-
- All Implemented Interfaces:
GoogleCloudStorageFileSystem
public class GoogleCloudStorageFileSystemImpl extends Object implements GoogleCloudStorageFileSystem
Provides FS semantics over GCS based on Objects API
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGoogleCloudStorageFileSystemImpl.PathTypeHint
-
Field Summary
Fields Modifier and Type Field Description static ListFileOptionsDELETE_RENAME_LIST_OPTIONS-
Fields inherited from interface com.google.cloud.hadoop.gcsio.GoogleCloudStorageFileSystem
GCS_ROOT, SCHEME
-
-
Constructor Summary
Constructors Constructor Description GoogleCloudStorageFileSystemImpl(com.google.auth.Credentials credentials, GoogleCloudStorageFileSystemOptions options)Constructs an instance of GoogleCloudStorageFileSystem.GoogleCloudStorageFileSystemImpl(com.google.auth.Credentials credentials, Function<List<AccessBoundary>,String> downscopedAccessTokenFn, GoogleCloudStorageFileSystemOptions options)Constructs an instance of GoogleCloudStorageFileSystem.GoogleCloudStorageFileSystemImpl(GoogleCloudStorage gcs, GoogleCloudStorageFileSystemOptions options)GoogleCloudStorageFileSystemImpl(CheckedFunction<GoogleCloudStorageOptions,GoogleCloudStorage,IOException> gcsFn, GoogleCloudStorageFileSystemOptions options)Constructs a GoogleCloudStorageFilesystem based on an already-configured underlying GoogleCloudStoragegcs.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Releases resources used by this instance.voidcompose(List<URI> sources, URI destination, String contentType)Composes inputs into a single GCS object.WritableByteChannelcreate(URI path, CreateFileOptions createOptions)Creates and opens an object for writing.voiddelete(URI path, boolean recursive)Deletes one or more items indicated by the given path.booleanexists(URI path)Indicates whether the given item exists.FileInfogetFileInfo(URI path)Gets information about the given path item.FileInfogetFileInfoObject(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.FileInfogetFileInfoWithHint(URI path, GoogleCloudStorageFileSystemImpl.PathTypeHint pathTypeHint)Gets information about the given path item with hint providing the path type (file vs directory).GoogleCloudStoragegetGcs()Retrieve our internal gcs.GoogleCloudStorageFileSystemOptionsgetOptions()Retrieve the options that were used to create this GoogleCloudStorageFileSystem.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, ListFileOptions listOptions)Equivalent to a recursive listing ofprefix, except thatprefixdoesn'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 toGoogleCloudStorageFileSystem.listFileInfoForPrefix(java.net.URI)but returnsFileInfos listed by single request (1 page).List<FileInfo>listFileInfoStartingFrom(URI startsFrom, ListFileOptions listOptions)Return all the files which are lexicographically equal or greater than the provided path.GoogleCloudStorage.ListPage<FolderInfo>listFoldersInfoForPrefixPage(URI prefix, ListFolderOptions listFolderOptions, String pageToken)Returns the list of folder resources in the prefix.voidmkdir(URI path)Creates a directory at the specified path.voidmkdirs(URI path)Creates a directory at the specified path.static CreateObjectOptionsobjectOptionsFromFileOptions(CreateFileOptions options)ConvertCreateFileOptionstoCreateObjectOptions.SeekableByteChannelopen(FileInfo fileInfo, GoogleCloudStorageReadOptions readOptions)Opens an object for reading usingFileInfo.SeekableByteChannelopen(URI path, GoogleCloudStorageReadOptions readOptions)Opens an object for reading.voidrename(URI src, URI dst)Renames the given item's path.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.cloud.hadoop.gcsio.GoogleCloudStorageFileSystem
create, listFileInfo, listFileInfoForPrefix, listFileInfoForPrefixPage, listFileInfoStartingFrom, open
-
-
-
-
Field Detail
-
DELETE_RENAME_LIST_OPTIONS
public static final ListFileOptions DELETE_RENAME_LIST_OPTIONS
-
-
Constructor Detail
-
GoogleCloudStorageFileSystemImpl
public GoogleCloudStorageFileSystemImpl(com.google.auth.Credentials credentials, GoogleCloudStorageFileSystemOptions options) throws IOExceptionConstructs an instance of GoogleCloudStorageFileSystem.- Parameters:
credentials- OAuth2 credentials that allows access to GCS.options- Options for how this filesystem should operate and configure its underlying storage.- Throws:
IOException
-
GoogleCloudStorageFileSystemImpl
public GoogleCloudStorageFileSystemImpl(com.google.auth.Credentials credentials, Function<List<AccessBoundary>,String> downscopedAccessTokenFn, GoogleCloudStorageFileSystemOptions options) throws IOExceptionConstructs an instance of GoogleCloudStorageFileSystem.- Parameters:
credentials- OAuth2 credentials 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.- Throws:
IOException
-
GoogleCloudStorageFileSystemImpl
public GoogleCloudStorageFileSystemImpl(CheckedFunction<GoogleCloudStorageOptions,GoogleCloudStorage,IOException> gcsFn, GoogleCloudStorageFileSystemOptions options) throws IOException
Constructs a GoogleCloudStorageFilesystem based on an already-configured underlying GoogleCloudStoragegcs. Any options pertaining to GCS creation will be ignored.- Throws:
IOException
-
GoogleCloudStorageFileSystemImpl
public GoogleCloudStorageFileSystemImpl(GoogleCloudStorage gcs, GoogleCloudStorageFileSystemOptions options)
-
-
Method Detail
-
getOptions
public GoogleCloudStorageFileSystemOptions getOptions()
Description copied from interface:GoogleCloudStorageFileSystemRetrieve the options that were used to create this GoogleCloudStorageFileSystem.- Specified by:
getOptionsin interfaceGoogleCloudStorageFileSystem
-
objectOptionsFromFileOptions
public static CreateObjectOptions objectOptionsFromFileOptions(CreateFileOptions options)
ConvertCreateFileOptionstoCreateObjectOptions.
-
create
public WritableByteChannel create(URI path, CreateFileOptions createOptions) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemCreates and opens an object for writing.- Specified by:
createin interfaceGoogleCloudStorageFileSystem- Parameters:
path- Object full path of the form gs://bucket/object-path.- Returns:
- A channel for writing to the given object.
- Throws:
IOException
-
open
public SeekableByteChannel open(URI path, GoogleCloudStorageReadOptions readOptions) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemOpens an object for reading.- Specified by:
openin interfaceGoogleCloudStorageFileSystem- Parameters:
path- Object full path of the form gs://bucket/object-path.readOptions- Fine-grained options for behaviors of retries, buffering, etc.- Returns:
- A channel for reading from the given object.
- Throws:
FileNotFoundException- if the given path does not exist.IOException- if object exists but cannot be opened.
-
open
public SeekableByteChannel open(FileInfo fileInfo, GoogleCloudStorageReadOptions readOptions) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemOpens an object for reading usingFileInfo.- Specified by:
openin interfaceGoogleCloudStorageFileSystem- Parameters:
fileInfo- contains metadata information about the filereadOptions- readOptions fine-grained options specifying things like retry settings, buffering, etc.- Returns:
- Seekable Byte Channel to enable file open
- Throws:
IOException- IOException on IO Error
-
delete
public void delete(URI path, boolean recursive) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemDeletes one or more items indicated by the given path.If path points to a directory:
- if recursive is true, all items under that path are recursively deleted followed by deletion of the directory.
- else,
- the directory is deleted if it is empty,
- else, an IOException is thrown.
The recursive parameter is ignored for a file.
- Specified by:
deletein interfaceGoogleCloudStorageFileSystem- Parameters:
path- Path of the item to delete.recursive- If true, all sub-items are also deleted.- Throws:
FileNotFoundException- if the given path does not exist.IOException
-
listFoldersInfoForPrefixPage
public GoogleCloudStorage.ListPage<FolderInfo> listFoldersInfoForPrefixPage(URI prefix, ListFolderOptions listFolderOptions, String pageToken) throws IOException
Returns the list of folder resources in the prefix. It lists all the folder resources- Specified by:
listFoldersInfoForPrefixPagein interfaceGoogleCloudStorageFileSystem- Parameters:
prefix- the prefix to use to list all matching folder resources.pageToken- the page token to listlistFolderOptions- the page token to list- Throws:
IOException
-
exists
public boolean exists(URI path) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemIndicates whether the given item exists.- Specified by:
existsin interfaceGoogleCloudStorageFileSystem- Parameters:
path- Path of the item to check.- Returns:
- true if the given item exists, false otherwise.
- Throws:
IOException
-
mkdirs
public void mkdirs(URI path) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemCreates a directory at the specified path. Also creates any parent directories as necessary. Similar to 'mkdir -p' command.- Specified by:
mkdirsin interfaceGoogleCloudStorageFileSystem- Parameters:
path- Path of the directory to create.- Throws:
IOException
-
rename
public void rename(URI src, URI dst) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemRenames the given item's path.The operation is disallowed if any of the following is true:
- src equals GCS_ROOT
- src is a file and dst equals GCS_ROOT
- src does not exist
- dst is a file that already exists
- parent of the destination does not exist
Otherwise, the expected behavior is as follows:
- if src is a directory:
- if dst is an existing file then disallowed
- if dst is a directory then rename the directory
- if src is a file:
- if dst is a file then rename the file.
- if dst is a directory then similar to the previous case after appending src file-name to dst
Note: This function is very expensive to call for directories that have many sub-items.
- Specified by:
renamein interfaceGoogleCloudStorageFileSystem- Parameters:
src- Path of the item to rename.dst- New path of the item.- Throws:
FileNotFoundException- if src does not exist.IOException
-
compose
public void compose(List<URI> sources, URI destination, String contentType) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemComposes inputs into a single GCS object. This performs a GCS Compose. Objects will be composed according to the order they appear in the input. The destination object, if already present, will be overwritten. Sources and destination are assumed to be in the same bucket.- Specified by:
composein interfaceGoogleCloudStorageFileSystem- Parameters:
sources- the list of URIs to be composeddestination- the resulting URI with composed sourcescontentType- content-type of the composed object- Throws:
IOException- if the Compose operation was unsuccessful
-
listFileInfoForPrefix
public List<FileInfo> listFileInfoForPrefix(URI prefix, ListFileOptions listOptions) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemEquivalent to a recursive listing ofprefix, except thatprefixdoesn't have to represent an actual object but can just be a partial prefix string. The 'authority' component of theprefixmust be the complete authority, however; we can only list prefixes of objects, not buckets.- Specified by:
listFileInfoForPrefixin interfaceGoogleCloudStorageFileSystem- Parameters:
prefix- the prefix to use to list all matching objects.- Throws:
IOException
-
listFileInfoForPrefixPage
public GoogleCloudStorage.ListPage<FileInfo> listFileInfoForPrefixPage(URI prefix, ListFileOptions listOptions, String pageToken) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemEquivalent toGoogleCloudStorageFileSystem.listFileInfoForPrefix(java.net.URI)but returnsFileInfos listed by single request (1 page).- Specified by:
listFileInfoForPrefixPagein interfaceGoogleCloudStorageFileSystem- Parameters:
prefix- the prefix to use to list all matching objects.pageToken- the page token to list- Throws:
IOException
-
listFileInfo
public List<FileInfo> listFileInfo(URI path, ListFileOptions listOptions) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemIf the given path points to a directory then the information about its children is returned, otherwise information about the given file is returned.- Specified by:
listFileInfoin interfaceGoogleCloudStorageFileSystem- Parameters:
path- Given path.- Returns:
- Information about a file or children of a directory.
- Throws:
FileNotFoundException- if the given path does not exist.IOException
-
listFileInfoStartingFrom
public List<FileInfo> listFileInfoStartingFrom(URI startsFrom, ListFileOptions listOptions) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemReturn all the files which are lexicographically equal or greater than the provided path. This is an experimental API and can change without notice.- Specified by:
listFileInfoStartingFromin interfaceGoogleCloudStorageFileSystem- Parameters:
startsFrom- Given path.- Returns:
- Information about all the files which satisfies the criteria.
- Throws:
IOException
-
getFileInfo
public FileInfo getFileInfo(URI path) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemGets information about the given path item.- Specified by:
getFileInfoin interfaceGoogleCloudStorageFileSystem- Parameters:
path- The path we want information about.- Returns:
- Information about the given path item.
- Throws:
IOException
-
getFileInfoWithHint
public FileInfo getFileInfoWithHint(URI path, GoogleCloudStorageFileSystemImpl.PathTypeHint pathTypeHint) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemGets information about the given path item with hint providing the path type (file vs directory).- Specified by:
getFileInfoWithHintin interfaceGoogleCloudStorageFileSystem- Parameters:
path- The path we want information about.- Returns:
- Information about the given path item.
- Throws:
IOException
-
getFileInfoObject
public FileInfo getFileInfoObject(URI path) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemGets information about the given path item. Here path should be pointing to a gcs object and can't be a directory- Specified by:
getFileInfoObjectin interfaceGoogleCloudStorageFileSystem- Parameters:
path- The path we want information about.- Returns:
- Information about the given path item.
- Throws:
IOException
-
getFileInfos
public List<FileInfo> getFileInfos(List<URI> paths) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemGets information about each path in the given list; more efficient than calling getFileInfo() on each path individually in a loop.- Specified by:
getFileInfosin interfaceGoogleCloudStorageFileSystem- Parameters:
paths- List of paths.- Returns:
- Information about each path in the given list.
- Throws:
IOException
-
close
public void close()
Description copied from interface:GoogleCloudStorageFileSystemReleases resources used by this instance.- Specified by:
closein interfaceGoogleCloudStorageFileSystem
-
mkdir
public void mkdir(URI path) throws IOException
Description copied from interface:GoogleCloudStorageFileSystemCreates a directory at the specified path.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().
- Specified by:
mkdirin interfaceGoogleCloudStorageFileSystem- Throws:
IOException
-
getGcs
public GoogleCloudStorage getGcs()
Description copied from interface:GoogleCloudStorageFileSystemRetrieve our internal gcs.- Specified by:
getGcsin interfaceGoogleCloudStorageFileSystem
-
-