public interface Storage extends Service<StorageOptions>
| Modifier and Type | Interface and Description |
|---|---|
static class |
Storage.BlobField |
static class |
Storage.BlobGetOption
Class for specifying blob get options.
|
static class |
Storage.BlobListOption
Class for specifying blob list options.
|
static class |
Storage.BlobSourceOption
Class for specifying blob source options.
|
static class |
Storage.BlobTargetOption
Class for specifying blob target options.
|
static class |
Storage.BlobWriteOption
Class for specifying blob write options.
|
static class |
Storage.BucketField |
static class |
Storage.BucketGetOption
Class for specifying bucket source options.
|
static class |
Storage.BucketListOption
Class for specifying bucket list options.
|
static class |
Storage.BucketSourceOption
Class for specifying bucket source options.
|
static class |
Storage.BucketTargetOption
Class for specifying bucket target options.
|
static class |
Storage.ComposeRequest
A class to contain all information needed for a Google Cloud Storage Compose operation.
|
static class |
Storage.CopyRequest
A class to contain all information needed for a Google Cloud Storage Copy operation.
|
static class |
Storage.PredefinedAcl |
static class |
Storage.SignUrlOption
Class for specifying signed URL options.
|
| Modifier and Type | Method and Description |
|---|---|
StorageBatch |
batch()
Creates a new empty batch for grouping multiple service calls in one underlying RPC call.
|
Blob |
compose(Storage.ComposeRequest composeRequest)
Sends a compose request.
|
CopyWriter |
copy(Storage.CopyRequest copyRequest)
Sends a copy request.
|
Blob |
create(BlobInfo blobInfo,
byte[] content,
Storage.BlobTargetOption... options)
Creates a new blob.
|
Blob |
create(BlobInfo blobInfo,
InputStream content,
Storage.BlobWriteOption... options)
Creates a new blob.
|
Blob |
create(BlobInfo blobInfo,
Storage.BlobTargetOption... options)
Creates a new blob with no content.
|
Bucket |
create(BucketInfo bucketInfo,
Storage.BucketTargetOption... options)
Creates a new bucket.
|
List<Boolean> |
delete(BlobId... blobIds)
Deletes the requested blobs.
|
boolean |
delete(BlobId blob)
Deletes the requested blob.
|
boolean |
delete(BlobId blob,
Storage.BlobSourceOption... options)
Deletes the requested blob.
|
List<Boolean> |
delete(Iterable<BlobId> blobIds)
Deletes the requested blobs.
|
boolean |
delete(String bucket,
Storage.BucketSourceOption... options)
Deletes the requested bucket.
|
boolean |
delete(String bucket,
String blob,
Storage.BlobSourceOption... options)
Deletes the requested blob.
|
List<Blob> |
get(BlobId... blobIds)
Gets the requested blobs.
|
Blob |
get(BlobId blob)
Returns the requested blob or
null if not found. |
Blob |
get(BlobId blob,
Storage.BlobGetOption... options)
Returns the requested blob or
null if not found. |
List<Blob> |
get(Iterable<BlobId> blobIds)
Gets the requested blobs.
|
Bucket |
get(String bucket,
Storage.BucketGetOption... options)
Returns the requested bucket or
null if not found. |
Blob |
get(String bucket,
String blob,
Storage.BlobGetOption... options)
Returns the requested blob or
null if not found. |
Page<Bucket> |
list(Storage.BucketListOption... options)
Lists the project's buckets.
|
Page<Blob> |
list(String bucket,
Storage.BlobListOption... options)
Lists the bucket's blobs.
|
byte[] |
readAllBytes(BlobId blob,
Storage.BlobSourceOption... options)
Reads all the bytes from a blob.
|
byte[] |
readAllBytes(String bucket,
String blob,
Storage.BlobSourceOption... options)
Reads all the bytes from a blob.
|
ReadChannel |
reader(BlobId blob,
Storage.BlobSourceOption... options)
Returns a channel for reading the blob's content.
|
ReadChannel |
reader(String bucket,
String blob,
Storage.BlobSourceOption... options)
Returns a channel for reading the blob's content.
|
URL |
signUrl(BlobInfo blobInfo,
long duration,
TimeUnit unit,
Storage.SignUrlOption... options)
Generates a signed URL for a blob.
|
List<Blob> |
update(BlobInfo... blobInfos)
Updates the requested blobs.
|
Blob |
update(BlobInfo blobInfo)
Updates blob information.
|
Blob |
update(BlobInfo blobInfo,
Storage.BlobTargetOption... options)
Updates blob information.
|
Bucket |
update(BucketInfo bucketInfo,
Storage.BucketTargetOption... options)
Updates bucket information.
|
List<Blob> |
update(Iterable<BlobInfo> blobInfos)
Updates the requested blobs.
|
WriteChannel |
writer(BlobInfo blobInfo,
Storage.BlobWriteOption... options)
Creates a blob and return a channel for writing its content.
|
Bucket create(BucketInfo bucketInfo, Storage.BucketTargetOption... options)
StorageException - upon failureBlob create(BlobInfo blobInfo, Storage.BlobTargetOption... options)
StorageException - upon failureBlob create(BlobInfo blobInfo, byte[] content, Storage.BlobTargetOption... options)
content. For large content,
writer(com.google.cloud.storage.BlobInfo, com.google.cloud.storage.Storage.BlobWriteOption...) is recommended as it uses resumable upload. MD5 and CRC32C hashes of
content are computed and used for validating transferred data.StorageException - upon failureBlob create(BlobInfo blobInfo, InputStream content, Storage.BlobWriteOption... options)
content. For large content,
writer(com.google.cloud.storage.BlobInfo, com.google.cloud.storage.Storage.BlobWriteOption...) is recommended as it uses resumable upload. By default any md5 and crc32c
values in the given blobInfo are ignored unless requested via the
BlobWriteOption.md5Match and BlobWriteOption.crc32cMatch options. The given
input stream is closed upon success.StorageException - upon failureBucket get(String bucket, Storage.BucketGetOption... options)
null if not found.StorageException - upon failureBlob get(String bucket, String blob, Storage.BlobGetOption... options)
null if not found.StorageException - upon failureBlob get(BlobId blob, Storage.BlobGetOption... options)
null if not found.StorageException - upon failureBlob get(BlobId blob)
null if not found.StorageException - upon failurePage<Bucket> list(Storage.BucketListOption... options)
StorageException - upon failurePage<Blob> list(String bucket, Storage.BlobListOption... options)
Storage.BlobListOption.currentDirectory() option is provided,
results are returned in a directory-like mode.StorageException - upon failureBucket update(BucketInfo bucketInfo, Storage.BucketTargetOption... options)
StorageException - upon failureBlob update(BlobInfo blobInfo, Storage.BlobTargetOption... options)
blobInfo. To replace metadata instead you first have to unset them. Unsetting metadata
can be done by setting the provided blobInfo's metadata to null.
Example usage of replacing blob's metadata:
service.update(BlobInfo.builder("bucket", "name").metadata(null).build());
service.update(BlobInfo.builder("bucket", "name").metadata(newMetadata).build());
StorageException - upon failureBlob update(BlobInfo blobInfo)
blobInfo. To replace metadata instead you first have to unset them. Unsetting metadata
can be done by setting the provided blobInfo's metadata to null.
Example usage of replacing blob's metadata:
service.update(BlobInfo.builder("bucket", "name").metadata(null).build());
service.update(BlobInfo.builder("bucket", "name").metadata(newMetadata).build());
StorageException - upon failureboolean delete(String bucket, Storage.BucketSourceOption... options)
true if bucket was deleted, false if it was not foundStorageException - upon failureboolean delete(String bucket, String blob, Storage.BlobSourceOption... options)
true if blob was deleted, false if it was not foundStorageException - upon failureboolean delete(BlobId blob, Storage.BlobSourceOption... options)
true if blob was deleted, false if it was not foundStorageException - upon failureboolean delete(BlobId blob)
true if blob was deleted, false if it was not foundStorageException - upon failureBlob compose(Storage.ComposeRequest composeRequest)
StorageException - upon failureCopyWriter copy(Storage.CopyRequest copyRequest)
BlobInfo to the
CopyRequest using either
Storage.CopyRequest.Builder.target(BlobInfo, Storage.BlobTargetOption...) or
Storage.CopyRequest.Builder.target(BlobInfo, Iterable).
This method returns a CopyWriter object for the provided CopyRequest. If
source and destination objects share the same location and storage class the source blob is
copied with one request and CopyWriter.result() immediately returns, regardless of the
Storage.CopyRequest.megabytesCopiedPerChunk parameter. If source and destination have different
location or storage class CopyWriter.result() might issue multiple RPC calls depending
on blob's size.
Example usage of copy:
BlobInfo blob = service.copy(copyRequest).result();
To explicitly issue chunk copy requests use CopyWriter.copyChunk() instead:
CopyWriter copyWriter = service.copy(copyRequest);
while (!copyWriter.isDone()) {
copyWriter.copyChunk();
}
BlobInfo blob = copyWriter.result();
CopyWriter object that can be used to get information on the newly created
blob or to complete the copy if more than one RPC request is neededStorageException - upon failurebyte[] readAllBytes(String bucket, String blob, Storage.BlobSourceOption... options)
StorageException - upon failurebyte[] readAllBytes(BlobId blob, Storage.BlobSourceOption... options)
StorageException - upon failureStorageBatch batch()
Example of using a batch request to delete, update and get a blob:
StorageBatch batch = storage.batch();
BlobId firstBlob = BlobId.of("bucket", "blob1"));
BlobId secondBlob = BlobId.of("bucket", "blob2"));
batch.delete(firstBlob).notify(new BatchResult.Callback<Boolean, StorageException>() {
public void success(Boolean result) {
// deleted successfully
}
public void error(StorageException exception) {
// delete failed
}
});
batch.update(BlobInfo.builder(secondBlob).contentType("text/plain").build());
StorageBatchResult<Blob> result = batch.get(secondBlob);
batch.submit();
Blob blob = result.get(); // returns get result or throws StorageException
ReadChannel reader(String bucket, String blob, Storage.BlobSourceOption... options)
BlobInfo.etag() changes), subsequent calls to
blobReadChannel.read(ByteBuffer) may throw StorageException.
The Storage.BlobSourceOption.generationMatch(long) option can be provided to ensure that
blobReadChannel.read(ByteBuffer) calls will throw StorageException if blob`s
generation differs from the expected one.
StorageException - upon failureReadChannel reader(BlobId blob, Storage.BlobSourceOption... options)
blob.generation() is set
data corresponding to that generation is read. If blob.generation() is null
the blob's latest generation is read. If the blob changes while reading (i.e.
BlobInfo.etag() changes), subsequent calls to blobReadChannel.read(ByteBuffer)
may throw StorageException.
The Storage.BlobSourceOption.generationMatch() and
Storage.BlobSourceOption.generationMatch(long) options can be used to ensure that
blobReadChannel.read(ByteBuffer) calls will throw StorageException if the
blob`s generation differs from the expected one.
StorageException - upon failureWriteChannel writer(BlobInfo blobInfo, Storage.BlobWriteOption... options)
blobInfo are ignored unless requested via the
BlobWriteOption.md5Match and BlobWriteOption.crc32cMatch options.StorageException - upon failureURL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, Storage.SignUrlOption... options)
AuthCredentials.ServiceAccountAuthCredentials or an
AuthCredentials.AppEngineAuthCredentials was passed to
ServiceOptions.Builder.authCredentials(AuthCredentials) or the default credentials are
being used and the environment variable GOOGLE_APPLICATION_CREDENTIALS is set, then
signUrl will use that credentials to sign the URL. If the credentials passed to
StorageOptions do not implement ServiceAccountSigner (this is the case for
Compute Engine credentials and Google Cloud SDK credentials) then signUrl will throw an
IllegalStateException unless an implementation of ServiceAccountSigner is
passed using the Storage.SignUrlOption.signWith(ServiceAccountSigner) option.
A service account signer is looked for in the following order:
Storage.SignUrlOption.signWith(ServiceAccountSigner)
ServiceOptions.Builder.authCredentials(AuthCredentials)
StorageOptions
Example usage of creating a signed URL that is valid for 2 weeks, using the default credentials for signing the URL:
service.signUrl(BlobInfo.builder("bucket", "name").build(), 14, TimeUnit.DAYS);
Example usage of creating a signed URL passing the
Storage.SignUrlOption.signWith(ServiceAccountSigner) option, that will be used for signing the
URL:
service.signUrl(BlobInfo.builder("bucket", "name").build(), 14, TimeUnit.DAYS,
SignUrlOption.signWith(
AuthCredentials.createForJson(new FileInputStream("/path/to/key.json"))));
blobInfo - the blob associated with the signed URLduration - time until the signed URL expires, expressed in unit. The finest
granularity supported is 1 second, finer granularities will be truncatedunit - time unit of the duration parameteroptions - optional URL signing optionsIllegalStateException - if Storage.SignUrlOption.signWith(ServiceAccountSigner) was not
used and no implementation of ServiceAccountSigner was provided to
StorageOptionsIllegalArgumentException - if SignUrlOption.withMd5() option is used and
blobInfo.md5() is nullIllegalArgumentException - if SignUrlOption.withContentType() option is used and
blobInfo.contentType() is nullServiceAccountSigner.SigningException - if the attempt to sign the URL failedList<Blob> get(BlobId... blobIds)
blobIds - blobs to getBlob objects. If a blob does not exist or access to it
has been denied the corresponding item in the list is null.StorageException - upon failureList<Blob> get(Iterable<BlobId> blobIds)
blobIds - blobs to getBlob objects. If a blob does not exist or access to it
has been denied the corresponding item in the list is null.StorageException - upon failureList<Blob> update(BlobInfo... blobInfos)
BlobInfo objects. To replace metadata instead
you first have to unset them. Unsetting metadata can be done by setting the provided
BlobInfo objects metadata to null. See
update(BlobInfo) for a code example.blobInfos - blobs to updateBlob objects. If a blob does not exist or access to it
has been denied the corresponding item in the list is null.StorageException - upon failureList<Blob> update(Iterable<BlobInfo> blobInfos)
BlobInfo objects. To replace metadata instead
you first have to unset them. Unsetting metadata can be done by setting the provided
BlobInfo objects metadata to null. See
update(BlobInfo) for a code example.blobInfos - blobs to updateBlob objects. If a blob does not exist or access to it
has been denied the corresponding item in the list is null.StorageException - upon failureList<Boolean> delete(BlobId... blobIds)
blobIds - blobs to deletetrue. If a blob was not found, deletion failed or access to the resource
was denied the corresponding item is false.StorageException - upon failureList<Boolean> delete(Iterable<BlobId> blobIds)
blobIds - blobs to deletetrue. If a blob was not found, deletion failed or access to the resource
was denied the corresponding item is false.StorageException - upon failureCopyright © 2016 Google. All rights reserved.