org.soyatec.windows.azure.blob
Class BlobContainerRest

java.lang.Object
  extended by org.soyatec.windows.azure.blob.BlobContainer
      extended by org.soyatec.windows.azure.blob.BlobContainerRest

public class BlobContainerRest
extends BlobContainer


Constructor Summary
BlobContainerRest(java.net.URI baseUri, boolean usePathStyleUris, java.lang.String accountName, java.lang.String containerName, java.lang.String base64Key, java.sql.Timestamp lastModified, TimeSpan timeOut, RetryPolicy retryPolicy)
           
 
Method Summary
 boolean copyBlob(java.lang.String destContainer, java.lang.String destBlobName, java.lang.String sourceBlobName)
          Copies a blob to a destination within the storage account.
 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.
 boolean createBlob(BlobProperties blobProperties, BlobContents blobContents, boolean overwrite)
          Create a new blob or overwrite an existing blob.
 boolean createContainer()
          Create the container if it does not exist.
 boolean createContainer(NameValueCollection metadata, ContainerAccessControl accessControl)
          Create the container with the specified access control if it does not exist
 boolean deleteBlob(java.lang.String name)
          Delete a blob with the given name.
 boolean deleteBlobIfNotModified(BlobProperties blob)
          Delete a blob with the given name if the blob has not been modified since it was last obtained.
 boolean deleteContainer()
          Deletes the current container.
 boolean doesBlobExist(java.lang.String blobName)
          Check if the blob container exists
 boolean doesContainerExist()
          Check if the blob container exists
 BlobProperties getBlob(java.lang.String name, BlobContents blobContents, boolean transferAsChunks)
          Get the blob contents and properties if the blob exists.
 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.
 BlobProperties getBlobProperties(java.lang.String name)
          Get the properties of the blob if it exists.
 ContainerAccessControl getContainerAccessControl()
          Get the access control permissions associated with the container.
 ContainerProperties getContainerProperties()
          Get the properties for the container if it exists.
 java.util.Collection<BlobProperties> listBlobs(java.lang.String prefix, boolean combineCommonPrefixes)
          Enumerates all blobs with a given prefix.
 java.util.Collection<BlobProperties> listBlobs(java.lang.String prefix, boolean combineCommonPrefixes, int maxResults)
          Enumerates all blobs with a given prefix.
 void setContainerAccessControl(ContainerAccessControl acl)
          Set the access control permissions associated with the container.
 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.
 void updateBlobMetadata(BlobProperties blobProperties)
          Set the metadata of an existing blob.
 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 org.soyatec.windows.azure.blob.BlobContainer
getAccountName, getBaseUri, getBlockSize, getContainerName, getContainerUri, getLastModifiedTime, getRetryPolicy, getTimeout, isStopped, isUsePathStyleUris, setBlockSize, setContainerUri, setRetryPolicy, setTimeout, stopFetchProgress
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlobContainerRest

public BlobContainerRest(java.net.URI baseUri,
                         boolean usePathStyleUris,
                         java.lang.String accountName,
                         java.lang.String containerName,
                         java.lang.String base64Key,
                         java.sql.Timestamp lastModified,
                         TimeSpan timeOut,
                         RetryPolicy retryPolicy)
Method Detail

createBlob

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

Specified by:
createBlob in class BlobContainer
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 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.

Specified by:
updateBlobIfNotModified in class BlobContainer
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

createContainer

public boolean createContainer()
                        throws StorageException
Description copied from class: BlobContainer
Create the container if it does not exist. The container is created with private access control and no metadata.

Specified by:
createContainer in class BlobContainer
Returns:
true if the container was created. false if the container already exists
Throws:
StorageException

createContainer

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

Specified by:
createContainer in class BlobContainer
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

doesContainerExist

public boolean doesContainerExist()
                           throws StorageException
Description copied from class: BlobContainer
Check if the blob container exists

Specified by:
doesContainerExist in class BlobContainer
Returns:
True if the container exists, false otherwise.
Throws:
StorageException

doesBlobExist

public boolean doesBlobExist(java.lang.String blobName)
                      throws StorageException
Description copied from class: BlobContainer
Check if the blob container exists

Specified by:
doesBlobExist in class BlobContainer
Returns:
true if the blob exists, false otherwise.
Throws:
StorageException

getContainerProperties

public ContainerProperties getContainerProperties()
                                           throws StorageException
Description copied from class: BlobContainer
Get the properties for the container if it exists.

Specified by:
getContainerProperties in class BlobContainer
Returns:
The properties for the container if it exists, null otherwise
Throws:
StorageException

setContainerAccessControl

public void setContainerAccessControl(ContainerAccessControl acl)
                               throws StorageException
Description copied from class: BlobContainer
Set the access control permissions associated with the container.

Specified by:
setContainerAccessControl in class BlobContainer
Parameters:
acl - The permission to set
Throws:
StorageException

getContainerAccessControl

public ContainerAccessControl getContainerAccessControl()
                                                 throws StorageException
Description copied from class: BlobContainer
Get the access control permissions associated with the container.

Specified by:
getContainerAccessControl in class BlobContainer
Throws:
StorageException

deleteContainer

public boolean deleteContainer()
                        throws StorageException
Description copied from class: BlobContainer
Deletes the current container.

Specified by:
deleteContainer in class BlobContainer
Returns:
Throws:
StorageException

deleteBlob

public boolean deleteBlob(java.lang.String name)
                   throws StorageException
Description copied from class: BlobContainer
Delete a blob with the given name.

Specified by:
deleteBlob in class BlobContainer
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 boolean deleteBlobIfNotModified(BlobProperties blob)
                                throws StorageException
Description copied from class: BlobContainer
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

Specified by:
deleteBlobIfNotModified in class BlobContainer
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

getBlob

public BlobProperties getBlob(java.lang.String name,
                              BlobContents blobContents,
                              boolean transferAsChunks)
                       throws StorageException
Description copied from class: BlobContainer
Get the blob contents and properties if the blob exists.

Specified by:
getBlob in class BlobContainer
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

listBlobs

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

Specified by:
listBlobs in class BlobContainer
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

listBlobs

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

Specified by:
listBlobs in class BlobContainer
Parameters:
prefix -
combineCommonPrefixes - If true common prefixes with "/" as separator
Returns:
The list of blob properties and common prefixes
Throws:
StorageException

getBlobIfModified

public boolean getBlobIfModified(BlobProperties blobProperties,
                                 BlobContents blobContents,
                                 boolean transferAsChunks)
                          throws StorageException
Description copied from class: BlobContainer
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.

Specified by:
getBlobIfModified in class BlobContainer
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 BlobProperties getBlobProperties(java.lang.String name)
                                 throws StorageException
Description copied from class: BlobContainer
Get the properties of the blob if it exists. This method is also the simplest way to check if a blob exists.

Specified by:
getBlobProperties in class BlobContainer
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

updateBlobMetadata

public void updateBlobMetadata(BlobProperties blobProperties)
                        throws StorageException
Description copied from class: BlobContainer
Set the metadata of an existing blob.

Specified by:
updateBlobMetadata in class BlobContainer
Parameters:
blobProperties - The blob properties object whose metadata is to be updated
Throws:
StorageException

copyBlob

public boolean copyBlob(java.lang.String destContainer,
                        java.lang.String destBlobName,
                        java.lang.String sourceBlobName)
                 throws StorageException
Description copied from class: BlobContainer
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.

Specified by:
copyBlob in class BlobContainer
Parameters:
destContainer - the destination blob container;
destBlobName - the destination blob's name;
sourceBlobName - the source blob's name;
Returns:
Throws:
StorageException

copyBlob

public boolean copyBlob(java.lang.String destContainer,
                        java.lang.String destBlobName,
                        java.lang.String sourceBlobName,
                        NameValueCollection metadata,
                        BlobConstraints constraints)
                 throws StorageException
Description copied from class: BlobContainer
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.

Specified by:
copyBlob in class BlobContainer
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

updateBlobMetadataIfNotModified

public boolean updateBlobMetadataIfNotModified(BlobProperties blobProperties)
                                        throws StorageException
Description copied from class: BlobContainer
Set the metadata of an existing blob if it has not been modified since it was last retrieved.

Specified by:
updateBlobMetadataIfNotModified in class BlobContainer
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