public class GCSFileIO extends java.lang.Object implements DelegateFileIO
Locations follow the conventions used by BlobId.fromGsUtilUri
that follow the
convention
gs://<bucket>/<blob_path>
Constructor and Description |
---|
GCSFileIO()
No-arg constructor to load the FileIO dynamically.
|
GCSFileIO(SerializableSupplier<com.google.cloud.storage.Storage> storageSupplier,
GCPProperties gcpProperties)
Constructor with custom storage supplier and GCP properties.
|
Modifier and Type | Method and Description |
---|---|
com.google.cloud.storage.Storage |
client() |
void |
close()
Close File IO to release underlying resources.
|
void |
deleteFile(java.lang.String path)
Delete the file at the given path.
|
void |
deleteFiles(java.lang.Iterable<java.lang.String> pathsToDelete)
Delete the files at the given paths.
|
void |
deletePrefix(java.lang.String prefix)
Delete all files under a prefix.
|
void |
initialize(java.util.Map<java.lang.String,java.lang.String> props)
Initialize File IO from catalog properties.
|
java.lang.Iterable<FileInfo> |
listPrefix(java.lang.String prefix)
Return an iterable of all files under a prefix.
|
InputFile |
newInputFile(java.lang.String path)
Get a
InputFile instance to read bytes from the file at the given path. |
InputFile |
newInputFile(java.lang.String path,
long length)
Get a
InputFile instance to read bytes from the file at the given path, with a known
file length. |
OutputFile |
newOutputFile(java.lang.String path)
Get a
OutputFile instance to write bytes to the file at the given path. |
java.util.Map<java.lang.String,java.lang.String> |
properties()
Returns the property map used to configure this FileIO
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
deleteFile, deleteFile, newInputFile, newInputFile, newInputFile
public GCSFileIO()
All fields are initialized by calling initialize(Map)
later.
public GCSFileIO(SerializableSupplier<com.google.cloud.storage.Storage> storageSupplier, GCPProperties gcpProperties)
Calling initialize(Map)
will overwrite information set in this
constructor.
storageSupplier
- storage suppliergcpProperties
- gcp propertiespublic InputFile newInputFile(java.lang.String path)
FileIO
InputFile
instance to read bytes from the file at the given path.newInputFile
in interface FileIO
public InputFile newInputFile(java.lang.String path, long length)
FileIO
InputFile
instance to read bytes from the file at the given path, with a known
file length.newInputFile
in interface FileIO
public OutputFile newOutputFile(java.lang.String path)
FileIO
OutputFile
instance to write bytes to the file at the given path.newOutputFile
in interface FileIO
public void deleteFile(java.lang.String path)
FileIO
deleteFile
in interface FileIO
public java.util.Map<java.lang.String,java.lang.String> properties()
FileIO
properties
in interface FileIO
public com.google.cloud.storage.Storage client()
public void initialize(java.util.Map<java.lang.String,java.lang.String> props)
FileIO
initialize
in interface FileIO
props
- catalog propertiespublic void close()
FileIO
Calling this method is only required when this FileIO instance is no longer expected to be used, and the resources it holds need to be explicitly released to avoid resource leaks.
public java.lang.Iterable<FileInfo> listPrefix(java.lang.String prefix)
SupportsPrefixOperations
Hierarchical file systems (e.g. HDFS) may impose additional restrictions like the prefix must fully match a directory whereas key/value object stores may allow for arbitrary prefixes.
listPrefix
in interface SupportsPrefixOperations
prefix
- prefix to listpublic void deletePrefix(java.lang.String prefix)
SupportsPrefixOperations
Hierarchical file systems (e.g. HDFS) may impose additional restrictions like the prefix must fully match a directory whereas key/value object stores may allow for arbitrary prefixes.
deletePrefix
in interface SupportsPrefixOperations
prefix
- prefix to deletepublic void deleteFiles(java.lang.Iterable<java.lang.String> pathsToDelete) throws BulkDeletionFailureException
SupportsBulkOperations
deleteFiles
in interface SupportsBulkOperations
pathsToDelete
- The paths to deleteBulkDeletionFailureException
- in case of failure to delete at least 1 file