org.soyatec.windows.azure.blob
Class BlobContainer

java.lang.Object
  extended by org.soyatec.windows.azure.blob.BlobContainer
Direct Known Subclasses:
BlobContainerRest

public abstract class BlobContainer
extends java.lang.Object

The BlobContainer class is used to access and enumerate blobs in the container. Storage key credentials are needed to access private blobs but not for public blobs.


Method Summary
abstract  boolean copyBlob(java.lang.String destContainer, java.lang.String destBlobName, java.lang.String sourceBlobName)
          Copies a blob to a destination within the storage account.
abstract  boolean copyBlob(java.lang.String destContainer, java.lang.String destBlobName, java.lang.String sourceBlobName, NameValueCollection metadata, BlobConstraints constraints)
          Copies a blob to a destination within the storage account.
abstract  boolean createBlob(BlobProperties blobProperties, BlobContents blobContents, boolean overwrite)
          Create a new blob or overwrite an existing blob.
abstract  boolean createContainer()
          Create the container if it does not exist.
abstract  boolean createContainer(NameValueCollection metadata, ContainerAccessControl accessControl)
          Create the container with the specified metadata and access control if it does not exist
abstract  boolean deleteBlob(java.lang.String name)
          Delete a blob with the given name.
abstract  boolean deleteBlobIfNotModified(BlobProperties blob)
          Delete a blob with the given name if the blob has not been modified since it was last obtained.
abstract  boolean deleteContainer()
          Deletes the current container.
abstract  boolean doesBlobExist(java.lang.String blobName)
          Check if the blob container exists
abstract  boolean doesContainerExist()
          Check if the blob container exists
 java.lang.String getAccountName()
           
 java.net.URI getBaseUri()
           
abstract  BlobProperties getBlob(java.lang.String name, BlobContents blobContents, boolean transferAsChunks)
          Get the blob contents and properties if the blob exists.
abstract  boolean getBlobIfModified(BlobProperties blobProperties, BlobContents blobContents, boolean transferAsChunks)
          Gets the blob contents and properties if the blob has not been modified since the time specified.
abstract  BlobProperties getBlobProperties(java.lang.String name)
          Get the properties of the blob if it exists.
 long getBlockSize()
           
abstract  ContainerAccessControl getContainerAccessControl()
          Get the access control permissions associated with the container.
 java.lang.String getContainerName()
           
abstract  ContainerProperties getContainerProperties()
          Get the properties for the container if it exists.
 java.net.URI getContainerUri()
           
 java.sql.Timestamp getLastModifiedTime()
           
 RetryPolicy getRetryPolicy()
           
 TimeSpan getTimeout()
           
 boolean isStopped()
           
 boolean isUsePathStyleUris()
          Indicates whether to use/generate path-style or host-style URIs.
abstract  java.util.Collection<BlobProperties> listBlobs(java.lang.String prefix, boolean combineCommonPrefixes)
          Enumerates all blobs with a given prefix.
abstract  java.util.Collection<BlobProperties> listBlobs(java.lang.String prefix, boolean combineCommonPrefixes, int maxResults)
          Enumerates all blobs with a given prefix.
 void setBlockSize(long blockSize)
           
abstract  void setContainerAccessControl(ContainerAccessControl acl)
          Set the access control permissions associated with the container.
 void setContainerUri(java.net.URI containerUri)
           
 void setRetryPolicy(RetryPolicy retryPolicy)
           
 void setTimeout(TimeSpan timeout)
           
 void stopFetchProgress(boolean stop)
          Set if the fetch process should be stopped.
abstract  boolean updateBlobIfNotModified(BlobProperties blobProperties, BlobContents contents)
          Updates an existing blob if it has not been modified since the specified time which is typically the last modified time of the blob when you retrieved it.
abstract  void updateBlobMetadata(BlobProperties blobProperties)
          Set the metadata of an existing blob.
abstract  boolean updateBlobMetadataIfNotModified(BlobProperties blobProperties)
          Set the metadata of an existing blob if it has not been modified since it was last retrieved.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createBlob

public abstract boolean createBlob(BlobProperties blobProperties,
                                   BlobContents blobContents,
                                   boolean overwrite)
                            throws StorageException
Create a new blob or overwrite an existing blob.

Parameters:
blobProperties - The properties of the blob
blobContents - The contents of the blob
overwrite - Should this request overwrite an existing blob
Returns:
true if the blob was created. false if the blob already exists and parameter "overwrite" was set to false. The LastModifiedTime property of is set as a result of this call. This method also has an effect on the ETag values that are managed by the service.
Throws:
StorageException

updateBlobIfNotModified

public abstract boolean updateBlobIfNotModified(BlobProperties blobProperties,
                                                BlobContents contents)
                                         throws StorageException
Updates an existing blob if it has not been modified since the specified time which is typically the last modified time of the blob when you retrieved it. Use this method to implement optimistic concurrency by avoiding clobbering changes to the blob made by another writer.

Parameters:
blobProperties - The properties of the blob. This object should be one previously obtained from a call to GetBlob or GetBlobProperties and have its LastModifiedTime property set.
contents - The contents of the blob. The contents of the blob should be readable
Returns:
true if the blob was updated. false if the blob has changed since the last time. The LastModifiedTime property of parameter "properties" is set as a result of this call.
Throws:
StorageException

updateBlobMetadata

public abstract void updateBlobMetadata(BlobProperties blobProperties)
                                 throws StorageException
Set the metadata of an existing blob.

Parameters:
blobProperties - The blob properties object whose metadata is to be updated
Throws:
StorageException

updateBlobMetadataIfNotModified

public abstract boolean updateBlobMetadataIfNotModified(BlobProperties blobProperties)
                                                 throws StorageException
Set the metadata of an existing blob if it has not been modified since it was last retrieved.

Parameters:
blobProperties - The blob properties object whose metadata is to be updated. Typically obtained by a previous call to GetBlob or GetBlobProperties
Returns:
true if the blob metadata was updated. false if it was not updated because the blob has been modified
Throws:
StorageException

createContainer

public abstract boolean createContainer()
                                 throws StorageException
Create the container if it does not exist. The container is created with private access control and no metadata.

Returns:
true if the container was created. false if the container already exists
Throws:
StorageStorageException
StorageException

createContainer

public abstract boolean createContainer(NameValueCollection metadata,
                                        ContainerAccessControl accessControl)
                                 throws StorageException
Create the container with the specified metadata and access control if it does not exist

Parameters:
metadata - The metadata for the container. Can be null to indicate no metadata
accessControl - The access control (public or private) with which to create the container
Returns:
true if the container was created. false if the container already exists
Throws:
StorageException

getBlob

public abstract BlobProperties getBlob(java.lang.String name,
                                       BlobContents blobContents,
                                       boolean transferAsChunks)
                                throws StorageException
Get the blob contents and properties if the blob exists.

Parameters:
name - The name of the blob
blobContents - Object in which the contents are returned. This object should contain a writable stream or should be a default constructed object.
transferAsChunks - Should the blob be gotten in pieces. This requires more round-trips, but will retry smaller pieces in case of failure.
Returns:
The properties of the blob if the blob exists.
Throws:
StorageException

getBlobIfModified

public abstract boolean getBlobIfModified(BlobProperties blobProperties,
                                          BlobContents blobContents,
                                          boolean transferAsChunks)
                                   throws StorageException
Gets the blob contents and properties if the blob has not been modified since the time specified. Use this method if you have cached the contents of a blob and want to avoid retrieving the blob if it has not changed since the last time you retrieved it.

Parameters:
blobProperties - The properties of the blob obtained from an earlier call to GetBlob. This parameter is updated by the call if the blob has been modified
blobContents - Contains the stream to which the contents of the blob are written if it has been modified
transferAsChunks - Should the blob be gotten in pieces. This requires more round-trips, but will retry smaller pieces in case of failure.
Returns:
true if the blob has been modified, false otherwise
Throws:
StorageException

getBlobProperties

public abstract BlobProperties getBlobProperties(java.lang.String name)
                                          throws StorageException
Get the properties of the blob if it exists. This method is also the simplest way to check if a blob exists.

Parameters:
name - The name of the blob
Returns:
The properties of the blob if it exists. null otherwise. // / The properties for the contents of the blob are not set
Throws:
StorageException

deleteContainer

public abstract boolean deleteContainer()
                                 throws StorageException
Deletes the current container.

Returns:
Throws:
StorageException

doesContainerExist

public abstract boolean doesContainerExist()
                                    throws StorageException
Check if the blob container exists

Returns:
True if the container exists, false otherwise.
Throws:
StorageException

doesBlobExist

public abstract boolean doesBlobExist(java.lang.String blobName)
                               throws StorageException
Check if the blob container exists

Parameters:
Name - of the BLOB.
Returns:
true if the blob exists, false otherwise.
Throws:
StorageException

listBlobs

public abstract java.util.Collection<BlobProperties> listBlobs(java.lang.String prefix,
                                                               boolean combineCommonPrefixes)
                                                        throws StorageException
Enumerates all blobs with a given prefix.

Parameters:
prefix -
combineCommonPrefixes - If true common prefixes with "/" as separator
Returns:
The list of blob properties and common prefixes
Throws:
StorageException

listBlobs

public abstract java.util.Collection<BlobProperties> listBlobs(java.lang.String prefix,
                                                               boolean combineCommonPrefixes,
                                                               int maxResults)
                                                        throws StorageException
Enumerates all blobs with a given prefix.

Parameters:
prefix -
combineCommonPrefixes - If true common prefixes with "/" as separator
maxResults - Specifies the maximum number of blobs to return per call to Azure storage. This does NOT affect list size returned by this function.
Returns:
The list of blob properties and common prefixes
Throws:
StorageException

setContainerAccessControl

public abstract void setContainerAccessControl(ContainerAccessControl acl)
                                        throws StorageException
Set the access control permissions associated with the container.

Parameters:
acl - The permission to set
Throws:
StorageException

getContainerAccessControl

public abstract ContainerAccessControl getContainerAccessControl()
                                                          throws StorageException
Get the access control permissions associated with the container.

Throws:
StorageException

getContainerProperties

public abstract ContainerProperties getContainerProperties()
                                                    throws StorageException
Get the properties for the container if it exists.

Returns:
The properties for the container if it exists, null otherwise
Throws:
StorageException

copyBlob

public abstract boolean copyBlob(java.lang.String destContainer,
                                 java.lang.String destBlobName,
                                 java.lang.String sourceBlobName)
                          throws StorageException
Copies a blob to a destination within the storage account.

Note
The Copy Blob operation is available only in the 2009-04-14 version of the Blob service. It is currently available only in Windows Azure storage, and not in development storage, nor within the StorageClient sample included in the Windows Azure SDK.

Parameters:
destContainer - the destination blob container;
destBlobName - the destination blob's name;
sourceBlobName - the source blob's name;
Returns:
Throws:
StorageException

copyBlob

public abstract boolean copyBlob(java.lang.String destContainer,
                                 java.lang.String destBlobName,
                                 java.lang.String sourceBlobName,
                                 NameValueCollection metadata,
                                 BlobConstraints constraints)
                          throws StorageException
Copies a blob to a destination within the storage account.

Note
The Copy Blob operation is available only in the 2009-04-14 version of the Blob service. It is currently available only in Windows Azure storage, and not in development storage, nor within the StorageClient sample included in the Windows Azure SDK.

Parameters:
destContainer - the destination blob container;
destBlobName - the destination blob's name;
sourceBlobName - the source blob's name;
metadata - The metadata for the Blob. Can be null to indicate no metadata;
constraints - The blob constraints for the blob copy operation.
Returns:
Throws:
StorageException

deleteBlob

public abstract boolean deleteBlob(java.lang.String name)
                            throws StorageException
Delete a blob with the given name.

Parameters:
name - The name of the blob
Returns:
true if the blob exists and was successfully deleted, false if the blob does not exist
Throws:
StorageException

deleteBlobIfNotModified

public abstract boolean deleteBlobIfNotModified(BlobProperties blob)
                                         throws StorageException
Delete a blob with the given name if the blob has not been modified since it was last obtained. Use this method for optimistic concurrency to avoid deleting a blob that has been modified since the last time you retrieved it

Parameters:
blob - A blob object (typically previously obtained from a GetBlob call)
Returns:
true if the blob exists and was successfully deleted, false if the blob does not exist or was not deleted because the blob was modified.
Throws:
StorageException

getBaseUri

public java.net.URI getBaseUri()
Returns:
The base URI of the blob storate service.

getAccountName

public java.lang.String getAccountName()
Returns:
The name of the storage account.

getContainerName

public java.lang.String getContainerName()
Returns:
The name of the blob container.

isUsePathStyleUris

public boolean isUsePathStyleUris()
Indicates whether to use/generate path-style or host-style URIs.

Returns:
true/false

getContainerUri

public java.net.URI getContainerUri()
Returns:
The URI of the container.

getLastModifiedTime

public java.sql.Timestamp getLastModifiedTime()
Returns:
The timestamp for last modification of container.

getTimeout

public TimeSpan getTimeout()
Returns:
The time out for each request to the storage service.

getRetryPolicy

public RetryPolicy getRetryPolicy()
Returns:
The retry policy used for retrying requests.

setTimeout

public void setTimeout(TimeSpan timeout)
Parameters:
timeout - The time out for each request to the storage service.

setRetryPolicy

public void setRetryPolicy(RetryPolicy retryPolicy)
Parameters:
retryPolicy - The retry policy used for retrying requests.

setContainerUri

public void setContainerUri(java.net.URI containerUri)
Parameters:
containerUri - The URI of the container.

stopFetchProgress

public void stopFetchProgress(boolean stop)
Set if the fetch process should be stopped.

Parameters:
stop -

isStopped

public boolean isStopped()
Returns:
Indicates whether the fetch process should be stopped.

getBlockSize

public long getBlockSize()
Returns:
The size of the blob.

setBlockSize

public void setBlockSize(long blockSize)
Parameters:
blockSize - The size of the blob.