public class Blob extends BlobInfo
Objects of this class are immutable. Operations that modify the blob like update(com.google.cloud.storage.Storage.BlobTargetOption...) and
copyTo(com.google.cloud.storage.BlobId, com.google.cloud.storage.Blob.BlobSourceOption...) return a new object. To get a Blob object with the most recent
information use reload(com.google.cloud.storage.Blob.BlobSourceOption...). Blob adds a layer of service-related functionality over
BlobInfo.
| Modifier and Type | Class and Description |
|---|---|
static class |
Blob.BlobSourceOption
Class for specifying blob source options when
Blob methods are used. |
static class |
Blob.Builder
Builder for
Blob. |
BlobInfo.ImmutableEmptyMap<K,V>| Modifier and Type | Method and Description |
|---|---|
byte[] |
content(Storage.BlobSourceOption... options)
Returns this blob's content.
|
CopyWriter |
copyTo(BlobId targetBlob,
Blob.BlobSourceOption... options)
Sends a copy request for the current blob to the target blob.
|
CopyWriter |
copyTo(String targetBucket,
Blob.BlobSourceOption... options)
Sends a copy request for the current blob to the target bucket, preserving its name.
|
CopyWriter |
copyTo(String targetBucket,
String targetBlob,
Blob.BlobSourceOption... options)
Sends a copy request for the current blob to the target blob.
|
boolean |
delete(Blob.BlobSourceOption... options)
Deletes this blob.
|
boolean |
equals(Object obj) |
boolean |
exists(Blob.BlobSourceOption... options)
Checks if this blob exists.
|
int |
hashCode() |
ReadChannel |
reader(Blob.BlobSourceOption... options)
Returns a
ReadChannel object for reading this blob's content. |
Blob |
reload(Blob.BlobSourceOption... options)
Fetches current blob's latest information.
|
URL |
signUrl(long duration,
TimeUnit unit,
Storage.SignUrlOption... options)
Generates a signed URL for this blob.
|
Storage |
storage()
Returns the blob's
Storage object used to issue requests. |
Blob.Builder |
toBuilder()
Returns a builder for the current blob.
|
Blob |
update(Storage.BlobTargetOption... options)
Updates the blob's information.
|
WriteChannel |
writer(Storage.BlobWriteOption... options)
Returns a
WriteChannel object for writing to this blob. |
acl, blobId, bucket, builder, builder, builder, builder, builder, cacheControl, componentCount, contentDisposition, contentEncoding, contentLanguage, contentType, crc32c, deleteTime, etag, generatedId, generation, isDirectory, md5, mediaLink, metadata, metageneration, name, owner, selfLink, size, toString, updateTimepublic boolean exists(Blob.BlobSourceOption... options)
options - blob read optionsStorageException - upon failurepublic byte[] content(Storage.BlobSourceOption... options)
options - blob read optionsStorageException - upon failurepublic Blob reload(Blob.BlobSourceOption... options)
null if the blob does not exist.options - blob read optionsBlob object with latest information or null if not foundStorageException - upon failurepublic Blob update(Storage.BlobTargetOption... options)
copyTo(com.google.cloud.storage.BlobId, com.google.cloud.storage.Blob.BlobSourceOption...) and
delete(com.google.cloud.storage.Blob.BlobSourceOption...) operations. A new Blob object is returned. By default no checks are
made on the metadata generation of the current blob. If you want to update the information only
if the current blob metadata are at their latest version use the metagenerationMatch
option: newBlob.update(BlobTargetOption.metagenerationMatch()).
Original metadata are merged with metadata in the provided in this blob. To replace
metadata instead you first have to unset them. Unsetting metadata can be done by setting this
blob's metadata to null.
Example usage of replacing blob's metadata:
blob.toBuilder().metadata(null).build().update();
blob.toBuilder().metadata(newMetadata).build().update();
options - update optionsBlob object with updated informationStorageException - upon failurepublic boolean delete(Blob.BlobSourceOption... options)
options - blob delete optionstrue if blob was deleted, false if it was not foundStorageException - upon failurepublic CopyWriter copyTo(BlobId targetBlob, Blob.BlobSourceOption... options)
targetBlob - target blob's idoptions - source blob optionsCopyWriter 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 failurepublic CopyWriter copyTo(String targetBucket, Blob.BlobSourceOption... options)
targetBucket - target bucket's nameoptions - source blob optionsCopyWriter 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 failurepublic CopyWriter copyTo(String targetBucket, String targetBlob, Blob.BlobSourceOption... options)
targetBucket - target bucket's nametargetBlob - target blob's nameoptions - source blob optionsCopyWriter 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 failurepublic ReadChannel reader(Blob.BlobSourceOption... options)
ReadChannel object for reading this blob's content.options - blob read optionsStorageException - upon failurepublic WriteChannel writer(Storage.BlobWriteOption... options)
WriteChannel object for writing to this blob. By default any md5 and
crc32c values in the current blob are ignored unless requested via the
BlobWriteOption.md5Match and BlobWriteOption.crc32cMatch options.options - target blob optionsStorageException - upon failurepublic URL signUrl(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:
blob.signUrl(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:
blob.signUrl(14, TimeUnit.DAYS, SignUrlOption.signWith(
AuthCredentials.createForJson(new FileInputStream("/path/to/key.json"))));
duration - time until the signed URL expires, expressed in unit. The finer
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 failedpublic Storage storage()
Storage object used to issue requests.public Blob.Builder toBuilder()
BlobInfoCopyright © 2016 Google. All rights reserved.