@DoesServiceRequest
    public void delete(TableRequestOptions options, OperationContext opContext) throws StorageException {
        if (opContext == null) {
            opContext = new OperationContext();
        }

        opContext.initialize();
        options = TableRequestOptions.populateAndApplyDefaults(options, this.tableServiceClient);

        Utility.assertNotNullOrEmpty("tableName", this.name);
        final DynamicTableEntity tableEntry = new DynamicTableEntity();
        tableEntry.getProperties().put(TableConstants.TABLE_NAME, new EntityProperty(this.name));

        TableOperation deleteOp = new TableOperation(tableEntry, TableOperationType.DELETE);
        deleteOp.execute(this.tableServiceClient, TableConstants.TABLES_SERVICE_TABLES_NAME, options, opContext);
    }

@ DoesServiceRequest public void delete ( TableRequestOptions options , OperationContext opContext ) throws StorageException { if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = TableRequestOptions . populateAndApplyDefaults ( options , this . tableServiceClient ) ; Utility . assertNotNullOrEmpty ( "tableName" , this . name ) ; final DynamicTableEntity tableEntry = new DynamicTableEntity ( ) ; tableEntry . getProperties ( ) . put ( TableConstants . TABLE_NAME , new EntityProperty ( this . name ) ) ; TableOperation deleteOp = new TableOperation ( tableEntry , TableOperationType . DELETE ) ; deleteOp . execute ( this . tableServiceClient , TableConstants . TABLES_SERVICE_TABLES_NAME , options , opContext ) ; }

Deletes the table from the storage service, using the specified request options and operation context.

@param options
A {@link TableRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudTableClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@throws StorageException
If a storage service error occurred during the operation.

Deletes the table from the storage service using the specified request options and operation context .


@DoesServiceRequest
    public boolean deleteIfExists(TableRequestOptions options, OperationContext opContext) throws StorageException {
        options = TableRequestOptions.populateAndApplyDefaults(options, this.tableServiceClient);

        if (this.exists(true, options, opContext)) {
            try {
                this.delete(options, opContext);
            }
            catch (StorageException ex) {
                if (ex.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
                        && StorageErrorCodeStrings.RESOURCE_NOT_FOUND.equals(ex.getErrorCode())) {
                    return false;
                }
                else {
                    throw ex;
                }
            }
            return true;
        }
        else {
            return false;
        }
    }

@ DoesServiceRequest public boolean deleteIfExists ( TableRequestOptions options , OperationContext opContext ) throws StorageException { options = TableRequestOptions . populateAndApplyDefaults ( options , this . tableServiceClient ) ; if ( this . exists ( true , options , opContext ) ) { try { this . delete ( options , opContext ) ; } catch ( StorageException ex ) { if ( ex . getHttpStatusCode ( ) == HttpURLConnection . HTTP_NOT_FOUND && StorageErrorCodeStrings . RESOURCE_NOT_FOUND . equals ( ex . getErrorCode ( ) ) ) { return false ; } else { throw ex ; } } return true ; } else { return false ; } }

Deletes the table from the storage service using the specified request options and operation context, if it
exists.

@param options
A {@link TableRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudTableClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@return A value of true if the table existed in the storage service and has been deleted, otherwise
false.

@throws StorageException
If a storage service error occurred during the operation.

Deletes the table from the storage service using the specified request options and operation context if it exists .


@DoesServiceRequest
    public void uploadPermissions(final TablePermissions permissions, TableRequestOptions options,
            OperationContext opContext) throws StorageException {
        if (opContext == null) {
            opContext = new OperationContext();
        }

        opContext.initialize();
        options = TableRequestOptions.populateAndApplyDefaults(options, this.tableServiceClient);

        ExecutionEngine.executeWithRetry(this.tableServiceClient, this,
                this.uploadPermissionsImpl(permissions, options), options.getRetryPolicyFactory(), opContext);
    }

@ DoesServiceRequest public void uploadPermissions ( final TablePermissions permissions , TableRequestOptions options , OperationContext opContext ) throws StorageException { if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = TableRequestOptions . populateAndApplyDefaults ( options , this . tableServiceClient ) ; ExecutionEngine . executeWithRetry ( this . tableServiceClient , this , this . uploadPermissionsImpl ( permissions , options ) , options . getRetryPolicyFactory ( ) , opContext ) ; }

Uploads the table's permissions using the specified request options and operation context.

@param permissions
A {@link TablePermissions} object that represents the permissions to upload.
@param options
A {@link TableRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudTableClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@throws StorageException
If a storage service error occurred.

Uploads the table s permissions using the specified request options and operation context .


@DoesServiceRequest
    public TablePermissions downloadPermissions(TableRequestOptions options, OperationContext opContext)
            throws StorageException {
        if (opContext == null) {
            opContext = new OperationContext();
        }

        opContext.initialize();
        options = TableRequestOptions.populateAndApplyDefaults(options, this.tableServiceClient);

        return ExecutionEngine.executeWithRetry(this.tableServiceClient, this, this.downloadPermissionsImpl(options),
                options.getRetryPolicyFactory(), opContext);
    }

@ DoesServiceRequest public TablePermissions downloadPermissions ( TableRequestOptions options , OperationContext opContext ) throws StorageException { if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = TableRequestOptions . populateAndApplyDefaults ( options , this . tableServiceClient ) ; return ExecutionEngine . executeWithRetry ( this . tableServiceClient , this , this . downloadPermissionsImpl ( options ) , options . getRetryPolicyFactory ( ) , opContext ) ; }

Downloads the permissions settings for the table using the specified request options and operation context.

@param options
A {@link TableRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudTableClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@return A {@link TablePermissions} object that represents the table's permissions.

@throws StorageException
If a storage service error occurred.

Downloads the permissions settings for the table using the specified request options and operation context .


protected static void applyBaseDefaultsInternal(final RequestOptions modifiedOptions) {
        Utility.assertNotNull("modifiedOptions", modifiedOptions);
        if (modifiedOptions.getRetryPolicyFactory() == null) {
            modifiedOptions.setRetryPolicyFactory(new RetryExponentialRetry());
        }

        if (modifiedOptions.getLocationMode() == null) {
            modifiedOptions.setLocationMode(LocationMode.PRIMARY_ONLY);
        }
    }

protected static void applyBaseDefaultsInternal ( final RequestOptions modifiedOptions ) { Utility . assertNotNull ( "modifiedOptions" , modifiedOptions ) ; if ( modifiedOptions . getRetryPolicyFactory ( ) == null ) { modifiedOptions . setRetryPolicyFactory ( new RetryExponentialRetry ( ) ) ; } if ( modifiedOptions . getLocationMode ( ) == null ) { modifiedOptions . setLocationMode ( LocationMode . PRIMARY_ONLY ) ; } }

Populates the default timeout, retry policy, and location mode from client if they are null.

@param modifiedOptions
The input options to copy from when applying defaults

Populates the default timeout retry policy and location mode from client if they are null .


public static StorageExtendedErrorInformation getExtendedErrorInformation(final InputStream stream)
            throws SAXException, IOException, ParserConfigurationException {
        SAXParser saxParser = Utility.getSAXParser();
        StorageErrorHandler handler = new StorageErrorHandler();
        saxParser.parse(stream, handler);

        return handler.errorInfo;
    }

public static StorageExtendedErrorInformation getExtendedErrorInformation ( final InputStream stream ) throws SAXException , IOException , ParserConfigurationException { SAXParser saxParser = Utility . getSAXParser ( ) ; StorageErrorHandler handler = new StorageErrorHandler ( ) ; saxParser . parse ( stream , handler ) ; return handler . errorInfo ; }

Gets the Extended Error information from the response stream.

@return the Extended Error information from the response stream
@throws ParserConfigurationException
@throws IOException
@throws SAXException

Gets the Extended Error information from the response stream .


public static AccessCondition generateIfSequenceNumberLessThanOrEqualCondition(long sequenceNumber) {
        AccessCondition retCondition = new AccessCondition();
        retCondition.ifSequenceNumberLessThanOrEqual = sequenceNumber;
        return retCondition;
    }

Returns an access condition such that an operation will be performed only if resource's current sequence
number is less than or equal to the specified value. This condition only applies to page blobs.

@param sequenceNumber
The value to compare to the current sequence number.

@return An AccessCondition object that represents the If-Sequence-Number-LE condition.

Returns an access condition such that an operation will be performed only if resource s current sequence number is less than or equal to the specified value . This condition only applies to page blobs .


public static AccessCondition generateIfSequenceNumberLessThanCondition(long sequenceNumber) {
        AccessCondition retCondition = new AccessCondition();
        retCondition.ifSequenceNumberLessThan = sequenceNumber;
        return retCondition;
    }

Returns an access condition such that an operation will be performed only if resource's current sequence
number is less than the specified value. This condition only applies to page blobs.

@param sequenceNumber
The value to compare to the current sequence number.

@return An AccessCondition object that represents the If-Sequence-Number-LT condition.

Returns an access condition such that an operation will be performed only if resource s current sequence number is less than the specified value . This condition only applies to page blobs .


public static AccessCondition generateIfSequenceNumberEqualCondition(long sequenceNumber) {
        AccessCondition retCondition = new AccessCondition();
        retCondition.ifSequenceNumberEqual = sequenceNumber;
        return retCondition;
    }

public static AccessCondition generateIfSequenceNumberEqualCondition ( long sequenceNumber ) { AccessCondition retCondition = new AccessCondition ( ) ; retCondition . ifSequenceNumberEqual = sequenceNumber ; return retCondition ; }

Returns an access condition such that an operation will be performed only if resource's current sequence
number is equal to the specified value. This condition only applies to page blobs.

@param sequenceNumber
The value to compare to the current sequence number.

@return An AccessCondition object that represents the If-Sequence-Number-EQ condition.

Returns an access condition such that an operation will be performed only if resource s current sequence number is equal to the specified value . This condition only applies to page blobs .


public void applyConditionToRequest(final HttpURLConnection request) {
        applyLeaseConditionToRequest(request);

        if (this.ifModifiedSinceDate != null) {
            request.setRequestProperty(Constants.HeaderConstants.IF_MODIFIED_SINCE,
                    Utility.getGMTTime(this.ifModifiedSinceDate));
        }

        if (this.ifUnmodifiedSinceDate != null) {
            request.setRequestProperty(Constants.HeaderConstants.IF_UNMODIFIED_SINCE,
                    Utility.getGMTTime(this.ifUnmodifiedSinceDate));
        }

        if (!Utility.isNullOrEmpty(this.ifMatchETag)) {
            request.setRequestProperty(Constants.HeaderConstants.IF_MATCH, this.ifMatchETag);
        }

        if (!Utility.isNullOrEmpty(this.ifNoneMatchETag)) {
            request.setRequestProperty(Constants.HeaderConstants.IF_NONE_MATCH, this.ifNoneMatchETag);
        }
    }

public void applyConditionToRequest ( final HttpURLConnection request ) { applyLeaseConditionToRequest ( request ) ; if ( this . ifModifiedSinceDate != null ) { request . setRequestProperty ( Constants . HeaderConstants . IF_MODIFIED_SINCE , Utility . getGMTTime ( this . ifModifiedSinceDate ) ) ; } if ( this . ifUnmodifiedSinceDate != null ) { request . setRequestProperty ( Constants . HeaderConstants . IF_UNMODIFIED_SINCE , Utility . getGMTTime ( this . ifUnmodifiedSinceDate ) ) ; } if ( ! Utility . isNullOrEmpty ( this . ifMatchETag ) ) { request . setRequestProperty ( Constants . HeaderConstants . IF_MATCH , this . ifMatchETag ) ; } if ( ! Utility . isNullOrEmpty ( this . ifNoneMatchETag ) ) { request . setRequestProperty ( Constants . HeaderConstants . IF_NONE_MATCH , this . ifNoneMatchETag ) ; } }

RESERVED FOR INTERNAL USE. Applies the access conditions to the request.

@param request
A java.net.HttpURLConnection object that represents the request
to which the condition is being applied.

RESERVED FOR INTERNAL USE . Applies the access conditions to the request .


public void applySourceConditionToRequest(final HttpURLConnection request) {
        if (!Utility.isNullOrEmpty(this.leaseID)) {
            // Unsupported
            throw new IllegalArgumentException(SR.LEASE_CONDITION_ON_SOURCE);
        }

        if (this.ifModifiedSinceDate != null) {
            request.setRequestProperty(
                    Constants.HeaderConstants.SOURCE_IF_MODIFIED_SINCE_HEADER,
                    Utility.getGMTTime(this.ifModifiedSinceDate));
        }

        if (this.ifUnmodifiedSinceDate != null) {
            request.setRequestProperty(Constants.HeaderConstants.SOURCE_IF_UNMODIFIED_SINCE_HEADER,
                    Utility.getGMTTime(this.ifUnmodifiedSinceDate));
        }

        if (!Utility.isNullOrEmpty(this.ifMatchETag)) {
            request.setRequestProperty(
                    Constants.HeaderConstants.SOURCE_IF_MATCH_HEADER,
                    this.ifMatchETag);
        }

        if (!Utility.isNullOrEmpty(this.ifNoneMatchETag)) {
            request.setRequestProperty(
                    Constants.HeaderConstants.SOURCE_IF_NONE_MATCH_HEADER,
                    this.ifNoneMatchETag);
        }
    }

public
void
applySourceConditionToRequest
(
final
HttpURLConnection
request
)
{
if
(
!
Utility
.
isNullOrEmpty
(
this
.
leaseID
)
)
{
// Unsupported
throw
new
IllegalArgumentException
(
SR
.
LEASE_CONDITION_ON_SOURCE
)
;
}
if
(
this
.
ifModifiedSinceDate
!=
)
{
request
.
setRequestProperty
(
Constants
.
HeaderConstants
.
SOURCE_IF_MODIFIED_SINCE_HEADER
,
Utility
.
getGMTTime
(
this
.
ifModifiedSinceDate
)
)
;
}
if
(
this
.
ifUnmodifiedSinceDate
!=
)
{
request
.
setRequestProperty
(
Constants
.
HeaderConstants
.
SOURCE_IF_UNMODIFIED_SINCE_HEADER
,
Utility
.
getGMTTime
(
this
.
ifUnmodifiedSinceDate
)
)
;
}
if
(
!
Utility
.
isNullOrEmpty
(
this
.
ifMatchETag
)
)
{
request
.
setRequestProperty
(
Constants
.
HeaderConstants
.
SOURCE_IF_MATCH_HEADER
,
this
.
ifMatchETag
)
;
}
if
(
!
Utility
.
isNullOrEmpty
(
this
.
ifNoneMatchETag
)
)
{
request
.
setRequestProperty
(
Constants
.
HeaderConstants
.
SOURCE_IF_NONE_MATCH_HEADER
,
this
.
ifNoneMatchETag
)
;
}
}

RESERVED FOR INTERNAL USE. Applies the source access conditions to the request.

@param request
A java.net.HttpURLConnection object that represents the request
to which the condition is being applied.

RESERVED FOR INTERNAL USE . Applies the source access conditions to the request .


public void applyAppendConditionToRequest(final HttpURLConnection request) {
        if (this.ifMaxSizeLessThanOrEqual != null) {
            request.setRequestProperty(Constants.HeaderConstants.IF_MAX_SIZE_LESS_THAN_OR_EQUAL,
                    this.ifMaxSizeLessThanOrEqual.toString());
        }

        if (this.ifAppendPositionEqual != null) {
            request.setRequestProperty(Constants.HeaderConstants.IF_APPEND_POSITION_EQUAL_HEADER,
                    this.ifAppendPositionEqual.toString());
        }
    }

public void applyAppendConditionToRequest ( final HttpURLConnection request ) { if ( this . ifMaxSizeLessThanOrEqual != null ) { request . setRequestProperty ( Constants . HeaderConstants . IF_MAX_SIZE_LESS_THAN_OR_EQUAL , this . ifMaxSizeLessThanOrEqual . toString ( ) ) ; } if ( this . ifAppendPositionEqual != null ) { request . setRequestProperty ( Constants . HeaderConstants . IF_APPEND_POSITION_EQUAL_HEADER , this . ifAppendPositionEqual . toString ( ) ) ; } }

RESERVED FOR INTERNAL USE. Applies the access condition to the request.

@param request
A java.net.HttpURLConnection object that represents the request to which the condition is
being applied.

@throws StorageException
If there is an error parsing the date value of the access condition.

RESERVED FOR INTERNAL USE . Applies the access condition to the request .


public void applyLeaseConditionToRequest(final HttpURLConnection request) {
        if (!Utility.isNullOrEmpty(this.leaseID)) {
            request.setRequestProperty(Constants.HeaderConstants.LEASE_ID_HEADER, this.leaseID);
        }
    }

public void applyLeaseConditionToRequest ( final HttpURLConnection request ) { if ( ! Utility . isNullOrEmpty ( this . leaseID ) ) { request . setRequestProperty ( Constants . HeaderConstants . LEASE_ID_HEADER , this . leaseID ) ; } }

RESERVED FOR INTERNAL USE. Applies the lease access condition to the request.

@param request
A java.net.HttpURLConnection object that represents the request
to which the condition is being applied.

RESERVED FOR INTERNAL USE . Applies the lease access condition to the request .


public void applySequenceConditionToRequest(final HttpURLConnection request) {
        if (this.ifSequenceNumberLessThanOrEqual != null) {
            request.setRequestProperty(
                    Constants.HeaderConstants.IF_SEQUENCE_NUMBER_LESS_THAN_OR_EQUAL,
                    this.ifSequenceNumberLessThanOrEqual.toString());
        }

        if (this.ifSequenceNumberLessThan != null) {
            request.setRequestProperty(
                    Constants.HeaderConstants.IF_SEQUENCE_NUMBER_LESS_THAN,
                    this.ifSequenceNumberLessThan.toString());
        }

        if (this.ifSequenceNumberEqual != null) {
            request.setRequestProperty(
                    Constants.HeaderConstants.IF_SEQUENCE_NUMBER_EQUAL,
                    this.ifSequenceNumberEqual.toString());
        }
    }

public void applySequenceConditionToRequest ( final HttpURLConnection request ) { if ( this . ifSequenceNumberLessThanOrEqual != null ) { request . setRequestProperty ( Constants . HeaderConstants . IF_SEQUENCE_NUMBER_LESS_THAN_OR_EQUAL , this . ifSequenceNumberLessThanOrEqual . toString ( ) ) ; } if ( this . ifSequenceNumberLessThan != null ) { request . setRequestProperty ( Constants . HeaderConstants . IF_SEQUENCE_NUMBER_LESS_THAN , this . ifSequenceNumberLessThan . toString ( ) ) ; } if ( this . ifSequenceNumberEqual != null ) { request . setRequestProperty ( Constants . HeaderConstants . IF_SEQUENCE_NUMBER_EQUAL , this . ifSequenceNumberEqual . toString ( ) ) ; } }

RESERVED FOR INTERNAL USE. Applies the sequence number access conditions to the request.

@param request
A java.net.HttpURLConnection object that represents the request
to which the condition is being applied.

RESERVED FOR INTERNAL USE . Applies the sequence number access conditions to the request .


public boolean verifyConditional(final String etag, final Date lastModified) {
        if (this.ifModifiedSinceDate != null) {
            // The IfModifiedSince has a special helper in HttpURLConnection, use it instead of manually setting the
            // header.
            if (!lastModified.after(this.ifModifiedSinceDate)) {
                return false;
            }
        }

        if (this.ifUnmodifiedSinceDate != null) {
            if (lastModified.after(this.ifUnmodifiedSinceDate)) {
                return false;
            }
        }

        if (!Utility.isNullOrEmpty(this.ifMatchETag)) {
            if (!this.ifMatchETag.equals(etag) && !this.ifMatchETag.equals("*")) {
                return false;
            }
        }

        if (!Utility.isNullOrEmpty(this.ifNoneMatchETag)) {
            if (this.ifNoneMatchETag.equals(etag)) {
                return false;
            }
        }

        return true;
    }

RESERVED FOR INTERNAL USE. Verifies the condition is satisfied.

@param etag
A String that represents the ETag to check.
@param lastModified
A java.util.Date object that represents the last modified date/time.

@return true if the condition is satisfied; otherwise, false.

RESERVED FOR INTERNAL USE . Verifies the condition is satisfied .


public static String combineFilters(String filterA, String operator, String filterB) {
        return String.format("(%s) %s (%s)", filterA, operator, filterB);
    }

public
static
String
combineFilters
(
String
filterA
,
String
operator
,
String
filterB
)
{
return
String
.
format
(
"(%s) %s (%s)"
,
filterA
,
operator
,
filterB
)
;
}

Creates a filter condition using the specified logical operator on two filter conditions.

@param filterA
A String which specifies the first formatted filter condition.
@param operator
A String which specifies Operators.AND or Operators.OR.
@param filterB
A String which specifies the first formatted filter condition.
@return
A String which represents the combined filter expression.

Creates a filter condition using the specified logical operator on two filter conditions .


protected final void setStorageUri(final StorageUri storageUri) {
        this.usePathStyleUris = Utility.determinePathStyleFromUri(storageUri.getPrimaryUri());
        this.storageUri = storageUri;
    }

protected final void setStorageUri ( final StorageUri storageUri ) { this . usePathStyleUris = Utility . determinePathStyleFromUri ( storageUri . getPrimaryUri ( ) ) ; this . storageUri = storageUri ; }

Sets the list of URIs for all locations.

@param storageUri
A {@link StorageUri} object which represents the list of URIs for all locations.

Sets the list of URIs for all locations .


public static <T extends SharedAccessPolicy> void writeSharedAccessIdentifiersToStream(
            final HashMap<String, T> sharedAccessPolicies, final StringWriter outWriter)
            throws IllegalArgumentException, IllegalStateException, IOException {
        Utility.assertNotNull("sharedAccessPolicies", sharedAccessPolicies);
        Utility.assertNotNull("outWriter", outWriter);

        final XmlSerializer xmlw = Utility.getXmlSerializer(outWriter);

        if (sharedAccessPolicies.keySet().size() > Constants.MAX_SHARED_ACCESS_POLICY_IDENTIFIERS) {
            final String errorMessage = String.format(SR.TOO_MANY_SHARED_ACCESS_POLICY_IDENTIFIERS,
                    sharedAccessPolicies.keySet().size(), Constants.MAX_SHARED_ACCESS_POLICY_IDENTIFIERS);

            throw new IllegalArgumentException(errorMessage);
        }

        // default is UTF8
        xmlw.startDocument(Constants.UTF8_CHARSET, true);
        xmlw.startTag(Constants.EMPTY_STRING, Constants.SIGNED_IDENTIFIERS_ELEMENT);

        for (final Entry<String, T> entry : sharedAccessPolicies.entrySet()) {
            final SharedAccessPolicy policy = entry.getValue();
            xmlw.startTag(Constants.EMPTY_STRING, Constants.SIGNED_IDENTIFIER_ELEMENT);

            // Set the identifier
            Utility.serializeElement(xmlw, Constants.ID, entry.getKey());

            xmlw.startTag(Constants.EMPTY_STRING, Constants.ACCESS_POLICY);

            // Set the Start Time
            Utility.serializeElement(xmlw, Constants.START, Utility
                    .getUTCTimeOrEmpty(policy.getSharedAccessStartTime()).toString());

            // Set the Expiry Time
            Utility.serializeElement(xmlw, Constants.EXPIRY,
                    Utility.getUTCTimeOrEmpty(policy.getSharedAccessExpiryTime()).toString());

            // Set the Permissions
            Utility.serializeElement(xmlw, Constants.PERMISSION, policy.permissionsToString());

            // end AccessPolicy
            xmlw.endTag(Constants.EMPTY_STRING, Constants.ACCESS_POLICY);
            // end SignedIdentifier
            xmlw.endTag(Constants.EMPTY_STRING, Constants.SIGNED_IDENTIFIER_ELEMENT);
        }

        // end SignedIdentifiers
        xmlw.endTag(Constants.EMPTY_STRING, Constants.SIGNED_IDENTIFIERS_ELEMENT);
        // end doc
        xmlw.endDocument();
    }

RESERVED FOR INTERNAL USE. Writes a collection of shared access policies to the specified stream in XML format.

@param <T>

@param sharedAccessPolicies
A collection of shared access policies
@param outWriter
a sink to write the output to.
@throws IOException
if there is an error writing the shared access identifiers.
@throws IllegalStateException
if there is an error writing the shared access identifiers.
@throws IllegalArgumentException
if there is an error writing the shared access identifiers.

RESERVED FOR INTERNAL USE . Writes a collection of shared access policies to the specified stream in XML format .


public static byte[] generateMessageRequestBody(final String message) throws IllegalArgumentException,
            IllegalStateException, IOException {
        final StringWriter outWriter = new StringWriter();
        final XmlSerializer xmlw = Utility.getXmlSerializer(outWriter);

        // default is UTF8
        xmlw.startDocument(Constants.UTF8_CHARSET, true);
        xmlw.startTag(Constants.EMPTY_STRING, QueueConstants.QUEUE_MESSAGE_ELEMENT);

        Utility.serializeElement(xmlw, QueueConstants.MESSAGE_TEXT_ELEMENT, message);

        // end QueueMessage_ELEMENT
        xmlw.endTag(Constants.EMPTY_STRING, QueueConstants.QUEUE_MESSAGE_ELEMENT);

        // end doc
        xmlw.endDocument();

        return outWriter.toString().getBytes(Constants.UTF8_CHARSET);
    }

public
static
byte
[
]
generateMessageRequestBody
(
final
String
message
)
throws
IllegalArgumentException
,
IllegalStateException
,
IOException
{
final
StringWriter
outWriter
=
new
StringWriter
(
)
;
final
XmlSerializer
xmlw
=
Utility
.
getXmlSerializer
(
outWriter
)
;
// default is UTF8
xmlw
.
startDocument
(
Constants
.
UTF8_CHARSET
,
true
)
;
xmlw
.
startTag
(
Constants
.
EMPTY_STRING
,
QueueConstants
.
QUEUE_MESSAGE_ELEMENT
)
;
Utility
.
serializeElement
(
xmlw
,
QueueConstants
.
MESSAGE_TEXT_ELEMENT
,
message
)
;
// end QueueMessage_ELEMENT
xmlw
.
endTag
(
Constants
.
EMPTY_STRING
,
QueueConstants
.
QUEUE_MESSAGE_ELEMENT
)
;
// end doc
xmlw
.
endDocument
(
)
;
return
outWriter
.
toString
(
)
.
getBytes
(
Constants
.
UTF8_CHARSET
)
;
}

Generates the message request body from a string containing the message.
The message must be encodable as UTF-8. To be included in a web request,
this message request body must be written to the output stream of the web
request.

@param message
A String containing the message to wrap in a message request body.

@return An array of byte containing the message request body
encoded as UTF-8.
@throws IOException
if there is an error writing the queue message.
@throws IllegalStateException
if there is an error writing the queue message.
@throws IllegalArgumentException
if there is an error writing the queue message.

Generates the message request body from a string containing the message . The message must be encodable as UTF - 8 . To be included in a web request this message request body must be written to the output stream of the web request .


private static void addCanonicalizedHeaders(final HttpURLConnection conn, final StringBuilder canonicalizedString) {
        // Look for header names that start with
        // HeaderNames.PrefixForStorageHeader
        // Then sort them in case-insensitive manner.

        final Map<String, List<String>> headers = conn.getRequestProperties();
        final ArrayList<String> httpStorageHeaderNameArray = new ArrayList<String>();

        for (final String key : headers.keySet()) {
            if (key.toLowerCase(Utility.LOCALE_US).startsWith(Constants.PREFIX_FOR_STORAGE_HEADER)) {
                httpStorageHeaderNameArray.add(key.toLowerCase(Utility.LOCALE_US));
            }
        }

        Collections.sort(httpStorageHeaderNameArray);

        // Now go through each header's values in the sorted order and append
        // them to the canonicalized string.
        for (final String key : httpStorageHeaderNameArray) {
            final StringBuilder canonicalizedElement = new StringBuilder(key);
            String delimiter = ":";
            final ArrayList<String> values = getHeaderValues(headers, key);

            boolean appendCanonicalizedElement = false;
            // Go through values, unfold them, and then append them to the
            // canonicalized element string.
            for (final String value : values) {
                if (value != null) {
                    appendCanonicalizedElement = true;
                }

                // Unfolding is simply removal of CRLF.
                final String unfoldedValue = CRLF.matcher(value)
                    .replaceAll(Matcher.quoteReplacement(Constants.EMPTY_STRING));

                // Append it to the canonicalized element string.
                canonicalizedElement.append(delimiter);
                canonicalizedElement.append(unfoldedValue);
                delimiter = ",";
            }

            // Now, add this canonicalized element to the canonicalized header
            // string.
            if (appendCanonicalizedElement) {
                appendCanonicalizedElement(canonicalizedString, canonicalizedElement.toString());
            }
        }
    }

Add x-ms- prefixed headers in a fixed order.

@param conn
the HttpURLConnection for the operation
@param canonicalizedString
the canonicalized string to add the canonicalized headerst to.

Add x - ms - prefixed headers in a fixed order .


protected static void appendCanonicalizedElement(final StringBuilder builder, final String element) {
        builder.append("\n");
        builder.append(element);
    }

protected static void appendCanonicalizedElement ( final StringBuilder builder , final String element ) { builder . append ( "\n" ) ; builder . append ( element ) ; }

Append a string to a string builder with a newline constant

@param builder
the StringBuilder object
@param element
the string to append.


protected static String canonicalizeHttpRequest(final java.net.URL address, final String accountName,
            final String method, final String contentType, final long contentLength, final String date,
            final HttpURLConnection conn) throws StorageException {

        // The first element should be the Method of the request.
        // I.e. GET, POST, PUT, or HEAD.
        final StringBuilder canonicalizedString = new StringBuilder(ExpectedBlobQueueCanonicalizedStringLength);
        canonicalizedString.append(conn.getRequestMethod());

        // The next elements are
        // If any element is missing it may be empty.
        appendCanonicalizedElement(canonicalizedString,
                Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.CONTENT_ENCODING));
        appendCanonicalizedElement(canonicalizedString,
                Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.CONTENT_LANGUAGE));
        appendCanonicalizedElement(canonicalizedString,
                contentLength <= 0 ? Constants.EMPTY_STRING : String.valueOf(contentLength));
        appendCanonicalizedElement(canonicalizedString,
                Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.CONTENT_MD5));
        appendCanonicalizedElement(canonicalizedString, contentType != null ? contentType : Constants.EMPTY_STRING);

        final String dateString = Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.DATE);
        // If x-ms-date header exists, Date should be empty string
        appendCanonicalizedElement(canonicalizedString, dateString.equals(Constants.EMPTY_STRING) ? date
                : Constants.EMPTY_STRING);

        appendCanonicalizedElement(canonicalizedString,
                Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.IF_MODIFIED_SINCE));
        appendCanonicalizedElement(canonicalizedString,
                Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.IF_MATCH));
        appendCanonicalizedElement(canonicalizedString,
                Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.IF_NONE_MATCH));
        appendCanonicalizedElement(canonicalizedString,
                Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.IF_UNMODIFIED_SINCE));
        appendCanonicalizedElement(canonicalizedString,
                Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.RANGE));

        addCanonicalizedHeaders(conn, canonicalizedString);

        appendCanonicalizedElement(canonicalizedString, getCanonicalizedResource(address, accountName));

        return canonicalizedString.toString();
    }

Constructs a canonicalized string from the request's headers that will be used to construct the signature string
for signing a Blob or Queue service request under the Shared Key Full authentication scheme.

@param address
the request URI
@param accountName
the account name associated with the request
@param method
the verb to be used for the HTTP request.
@param contentType
the content type of the HTTP request.
@param contentLength
the length of the content written to the outputstream in bytes, -1 if unknown
@param date
the date/time specification for the HTTP request
@param conn
the HttpURLConnection for the operation.
@return A canonicalized string.
@throws StorageException

Constructs a canonicalized string from the request s headers that will be used to construct the signature string for signing a Blob or Queue service request under the Shared Key Full authentication scheme .


protected static String canonicalizeTableHttpRequest(final java.net.URL address, final String accountName,
            final String method, final String contentType, final long contentLength, final String date,
            final HttpURLConnection conn) throws StorageException {
        // The first element should be the Method of the request.
        // I.e. GET, POST, PUT, or HEAD.
        final StringBuilder canonicalizedString = new StringBuilder(ExpectedTableCanonicalizedStringLength);
        canonicalizedString.append(conn.getRequestMethod());

        // The second element should be the MD5 value.
        // This is optional and may be empty.
        final String httpContentMD5Value = Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.CONTENT_MD5);
        appendCanonicalizedElement(canonicalizedString, httpContentMD5Value);

        // The third element should be the content type.
        appendCanonicalizedElement(canonicalizedString, contentType);

        // The fourth element should be the request date.
        // See if there's an storage date header.
        // If there's one, then don't use the date header.

        final String dateString = Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.DATE);
        // If x-ms-date header exists, Date should be that value.
        appendCanonicalizedElement(canonicalizedString, dateString.equals(Constants.EMPTY_STRING) ? date : dateString);

        appendCanonicalizedElement(canonicalizedString, getCanonicalizedResourceLite(address, accountName));

        return canonicalizedString.toString();
    }

Constructs a canonicalized string that will be used to construct the signature string
for signing a Table service request under the Shared Key authentication scheme.

@param address
the request URI
@param accountName
the account name associated with the request
@param method
the verb to be used for the HTTP request.
@param contentType
the content type of the HTTP request.
@param contentLength
the length of the content written to the outputstream in bytes, -1 if unknown
@param date
the date/time specification for the HTTP request
@param conn
the HttpURLConnection for the operation.
@return A canonicalized string.
@throws StorageException

Constructs a canonicalized string that will be used to construct the signature string for signing a Table service request under the Shared Key authentication scheme .


public static synchronized String computeHmac256(final StorageCredentials creds, final String value) throws InvalidKeyException {
        if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) {
            byte[] utf8Bytes = null;
            try {
                utf8Bytes = value.getBytes(Constants.UTF8_CHARSET);
            }
            catch (final UnsupportedEncodingException e) {
                throw new IllegalArgumentException(e);
            }
            return Base64.encode(((StorageCredentialsAccountAndKey) creds).getHmac256().doFinal(utf8Bytes));
        }
        else {
            return null;
        }
    }

public static synchronized String computeHmac256 ( final StorageCredentials creds , final String value ) throws InvalidKeyException { if ( creds . getClass ( ) . equals ( StorageCredentialsAccountAndKey . class ) ) { byte [ ] utf8Bytes = null ; try { utf8Bytes = value . getBytes ( Constants . UTF8_CHARSET ) ; } catch ( final UnsupportedEncodingException e ) { throw new IllegalArgumentException ( e ) ; } return Base64 . encode ( ( ( StorageCredentialsAccountAndKey ) creds ) . getHmac256 ( ) . doFinal ( utf8Bytes ) ) ; } else { return null ; } }

Computes a signature for the specified string using the HMAC-SHA256 algorithm.

@param value
The UTF-8-encoded string to sign.

@return A String that contains the HMAC-SHA256-encoded signature.

@throws InvalidKeyException
If the key is not a valid Base64-encoded string.

Computes a signature for the specified string using the HMAC - SHA256 algorithm .


public static void signTableRequest(final StorageCredentials creds, final java.net.HttpURLConnection request,
            final long contentLength, OperationContext opContext) throws InvalidKeyException, StorageException {
        if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) {
            opContext = opContext == null ? new OperationContext() : opContext;
            request.setRequestProperty(Constants.HeaderConstants.DATE, Utility.getGMTTime());

            final Canonicalizer canonicalizer = CanonicalizerFactory.getTableCanonicalizer(request);

            final String stringToSign = canonicalizer.canonicalize(request, creds.getAccountName(), contentLength);

            final String computedBase64Signature = StorageCredentialsHelper.computeHmac256(creds, stringToSign);

            Logger.debug(opContext, LogConstants.SIGNING, stringToSign);

            request.setRequestProperty(Constants.HeaderConstants.AUTHORIZATION,
                    String.format("%s %s:%s", "SharedKey", creds.getAccountName(), computedBase64Signature));
        }
    }

public
static
void
signTableRequest
(
final
StorageCredentials
creds
,
final
java
.
net
.
HttpURLConnection
request
,
final
long
contentLength
,
OperationContext
opContext
)
throws
InvalidKeyException
,
StorageException
{
if
(
creds
.
getClass
(
)
.
equals
(
StorageCredentialsAccountAndKey
.
class
)
)
{
opContext
=
opContext
==
new
OperationContext
(
)
:
opContext
;
request
.
setRequestProperty
(
Constants
.
HeaderConstants
.
DATE
,
Utility
.
getGMTTime
(
)
)
;
final
Canonicalizer
canonicalizer
=
CanonicalizerFactory
.
getTableCanonicalizer
(
request
)
;
final
String
stringToSign
=
canonicalizer
.
canonicalize
(
request
,
creds
.
getAccountName
(
)
,
contentLength
)
;
final
String
computedBase64Signature
=
StorageCredentialsHelper
.
computeHmac256
(
creds
,
stringToSign
)
;
Logger
.
debug
(
opContext
,
LogConstants
.
SIGNING
,
stringToSign
)
;
request
.
setRequestProperty
(
Constants
.
HeaderConstants
.
AUTHORIZATION
,
String
.
format
(
"%s %s:%s"
,
"SharedKey"
,
creds
.
getAccountName
(
)
,
computedBase64Signature
)
)
;
}
}

Signs a request using the specified operation context under the Shared Key authentication scheme.

@param request
An HttpURLConnection object that represents the request to sign.
@param contentLength
The length of the content written to the output stream. If unknown, specify -1.
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@throws InvalidKeyException
If the given key is invalid.
@throws StorageException
If a storage service error occurred.

Signs a request using the specified operation context under the Shared Key authentication scheme .


private static CloudQueueMessage getFirstOrNull(final Iterable<CloudQueueMessage> messages) {
        for (final CloudQueueMessage m : messages) {
            return m;
        }

        return null;
    }

private static CloudQueueMessage getFirstOrNull ( final Iterable < CloudQueueMessage > messages ) { for ( final CloudQueueMessage m : messages ) { return m ; } return null ; }

Gets the first message from a list of queue messages, if any.

@param messages
The Iterable collection of {@link CloudQueueMessage} objects to get the first message
from.

@return The first {@link CloudQueueMessage} from the list of queue messages, or null if the list is
empty.

Gets the first message from a list of queue messages if any .


@DoesServiceRequest
    public void addMessage(final CloudQueueMessage message, final int timeToLiveInSeconds,
            final int initialVisibilityDelayInSeconds, QueueRequestOptions options, OperationContext opContext)
            throws StorageException {
        Utility.assertNotNull("message", message);
        Utility.assertNotNull("messageContent", message.getMessageContentAsByte());
        Utility.assertInBounds("timeToLiveInSeconds", timeToLiveInSeconds, 0,
                QueueConstants.MAX_TIME_TO_LIVE_IN_SECONDS);

        final int realTimeToLiveInSeconds = timeToLiveInSeconds == 0 ? QueueConstants.MAX_TIME_TO_LIVE_IN_SECONDS
                : timeToLiveInSeconds;
        Utility.assertInBounds("initialVisibilityDelayInSeconds", initialVisibilityDelayInSeconds, 0,
                realTimeToLiveInSeconds - 1);

        if (opContext == null) {
            opContext = new OperationContext();
        }

        opContext.initialize();
        options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

        ExecutionEngine.executeWithRetry(this.queueServiceClient, this,
            this.addMessageImpl(message, realTimeToLiveInSeconds, initialVisibilityDelayInSeconds, options),
            options.getRetryPolicyFactory(), opContext);
    }

@ DoesServiceRequest public void addMessage ( final CloudQueueMessage message , final int timeToLiveInSeconds , final int initialVisibilityDelayInSeconds , QueueRequestOptions options , OperationContext opContext ) throws StorageException { Utility . assertNotNull ( "message" , message ) ; Utility . assertNotNull ( "messageContent" , message . getMessageContentAsByte ( ) ) ; Utility . assertInBounds ( "timeToLiveInSeconds" , timeToLiveInSeconds , 0 , QueueConstants . MAX_TIME_TO_LIVE_IN_SECONDS ) ; final int realTimeToLiveInSeconds = timeToLiveInSeconds == 0 ? QueueConstants . MAX_TIME_TO_LIVE_IN_SECONDS : timeToLiveInSeconds ; Utility . assertInBounds ( "initialVisibilityDelayInSeconds" , initialVisibilityDelayInSeconds , 0 , realTimeToLiveInSeconds - 1 ) ; if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = QueueRequestOptions . populateAndApplyDefaults ( options , this . queueServiceClient ) ; ExecutionEngine . executeWithRetry ( this . queueServiceClient , this , this . addMessageImpl ( message , realTimeToLiveInSeconds , initialVisibilityDelayInSeconds , options ) , options . getRetryPolicyFactory ( ) , opContext ) ; }

Adds a message to the back of the queue with the specified options.

@param message
A {@link CloudQueueMessage} object that specifies the message to add.
The message object is modified to include the message ID and pop receipt,
and can be used in subsequent calls to updateMessage and deleteMessage.

@param timeToLiveInSeconds
The maximum time to allow the message to be in the queue. A value of zero will set the time-to-live to
the service default value of seven days.

@param initialVisibilityDelayInSeconds
The length of time during which the message will be invisible, starting when it is added to the queue,
or 0 to make the message visible immediately. This value must be greater than or equal to zero and
less than or equal to the time-to-live value.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).

@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@throws StorageException
If a storage service error occurred during the operation.

Adds a message to the back of the queue with the specified options .


@DoesServiceRequest
    public void clear(QueueRequestOptions options, OperationContext opContext) throws StorageException {
        if (opContext == null) {
            opContext = new OperationContext();
        }

        opContext.initialize();
        options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

        ExecutionEngine.executeWithRetry(this.queueServiceClient, this, this.clearImpl(options),
                options.getRetryPolicyFactory(), opContext);
    }

@ DoesServiceRequest public void clear ( QueueRequestOptions options , OperationContext opContext ) throws StorageException { if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = QueueRequestOptions . populateAndApplyDefaults ( options , this . queueServiceClient ) ; ExecutionEngine . executeWithRetry ( this . queueServiceClient , this , this . clearImpl ( options ) , options . getRetryPolicyFactory ( ) , opContext ) ; }

Clears all messages from the queue, using the specified request options and operation context.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@throws StorageException
If a storage service error occurred during the operation.

Clears all messages from the queue using the specified request options and operation context .


@DoesServiceRequest
    public void create(QueueRequestOptions options, OperationContext opContext) throws StorageException {
        if (opContext == null) {
            opContext = new OperationContext();
        }

        opContext.initialize();
        options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

        ExecutionEngine.executeWithRetry(this.queueServiceClient, this, this.createImpl(options),
                options.getRetryPolicyFactory(), opContext);
    }

@ DoesServiceRequest public void create ( QueueRequestOptions options , OperationContext opContext ) throws StorageException { if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = QueueRequestOptions . populateAndApplyDefaults ( options , this . queueServiceClient ) ; ExecutionEngine . executeWithRetry ( this . queueServiceClient , this , this . createImpl ( options ) , options . getRetryPolicyFactory ( ) , opContext ) ; }

Creates the queue, using the specified request options and operation context.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@throws StorageException
If a storage service error occurred during the operation.

Creates the queue using the specified request options and operation context .


@DoesServiceRequest
    public boolean createIfNotExists(QueueRequestOptions options, OperationContext opContext) throws StorageException {
        options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

        boolean exists = this.exists(true, options, opContext);
        if (exists) {
            return false;
        }
        else {
            try {
                this.create(options, opContext);
                return true;
            }
            catch (StorageException e) {
                if (e.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT
                        && StorageErrorCodeStrings.QUEUE_ALREADY_EXISTS.equals(e.getErrorCode())) {
                    return false;
                }
                else {
                    throw e;
                }
            }
        }
    }

@ DoesServiceRequest public boolean createIfNotExists ( QueueRequestOptions options , OperationContext opContext ) throws StorageException { options = QueueRequestOptions . populateAndApplyDefaults ( options , this . queueServiceClient ) ; boolean exists = this . exists ( true , options , opContext ) ; if ( exists ) { return false ; } else { try { this . create ( options , opContext ) ; return true ; } catch ( StorageException e ) { if ( e . getHttpStatusCode ( ) == HttpURLConnection . HTTP_CONFLICT && StorageErrorCodeStrings . QUEUE_ALREADY_EXISTS . equals ( e . getErrorCode ( ) ) ) { return false ; } else { throw e ; } } } }

Creates the queue if it does not already exist, using the specified request options and operation context.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@return A value of true if the queue is created in the storage service, otherwise false
.

@throws StorageException
If a storage service error occurred during the operation.

Creates the queue if it does not already exist using the specified request options and operation context .


@DoesServiceRequest
    public void delete(QueueRequestOptions options, OperationContext opContext) throws StorageException {
        if (opContext == null) {
            opContext = new OperationContext();
        }

        opContext.initialize();
        options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

        ExecutionEngine.executeWithRetry(this.queueServiceClient, this, this.deleteImpl(options),
                options.getRetryPolicyFactory(), opContext);
    }

@ DoesServiceRequest public void delete ( QueueRequestOptions options , OperationContext opContext ) throws StorageException { if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = QueueRequestOptions . populateAndApplyDefaults ( options , this . queueServiceClient ) ; ExecutionEngine . executeWithRetry ( this . queueServiceClient , this , this . deleteImpl ( options ) , options . getRetryPolicyFactory ( ) , opContext ) ; }

Deletes the queue, using the specified request options and operation context.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@throws StorageException
If a storage service error occurred during the operation.

Deletes the queue using the specified request options and operation context .


@DoesServiceRequest
    public boolean deleteIfExists(QueueRequestOptions options, OperationContext opContext) throws StorageException {
        options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

        boolean exists = this.exists(true, options, opContext);
        if (exists) {
            try {
                this.delete(options, opContext);
                return true;
            }
            catch (StorageException e) {
                if (e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
                        && StorageErrorCodeStrings.QUEUE_NOT_FOUND.equals(e.getErrorCode())) {
                    return false;
                }
                else {
                    throw e;
                }
            }

        }
        else {
            return false;
        }
    }

@ DoesServiceRequest public boolean deleteIfExists ( QueueRequestOptions options , OperationContext opContext ) throws StorageException { options = QueueRequestOptions . populateAndApplyDefaults ( options , this . queueServiceClient ) ; boolean exists = this . exists ( true , options , opContext ) ; if ( exists ) { try { this . delete ( options , opContext ) ; return true ; } catch ( StorageException e ) { if ( e . getHttpStatusCode ( ) == HttpURLConnection . HTTP_NOT_FOUND && StorageErrorCodeStrings . QUEUE_NOT_FOUND . equals ( e . getErrorCode ( ) ) ) { return false ; } else { throw e ; } } } else { return false ; } }

Deletes the queue if it exists, using the specified request options and operation context.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@return A value of true if the queue existed in the storage service and has been deleted, otherwise
false.

@throws StorageException
If a storage service error occurred during the operation.

Deletes the queue if it exists using the specified request options and operation context .


@DoesServiceRequest
    public void deleteMessage(final CloudQueueMessage message, QueueRequestOptions options, OperationContext opContext)
            throws StorageException {
        Utility.assertNotNull("message", message);
        Utility.assertNotNullOrEmpty("messageId", message.getId());
        Utility.assertNotNullOrEmpty("popReceipt", message.getPopReceipt());

        if (opContext == null) {
            opContext = new OperationContext();
        }

        opContext.initialize();
        options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

        ExecutionEngine.executeWithRetry(this.queueServiceClient, this, this.deleteMessageImpl(message, options),
                options.getRetryPolicyFactory(), opContext);
    }

@ DoesServiceRequest public void deleteMessage ( final CloudQueueMessage message , QueueRequestOptions options , OperationContext opContext ) throws StorageException { Utility . assertNotNull ( "message" , message ) ; Utility . assertNotNullOrEmpty ( "messageId" , message . getId ( ) ) ; Utility . assertNotNullOrEmpty ( "popReceipt" , message . getPopReceipt ( ) ) ; if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = QueueRequestOptions . populateAndApplyDefaults ( options , this . queueServiceClient ) ; ExecutionEngine . executeWithRetry ( this . queueServiceClient , this , this . deleteMessageImpl ( message , options ) , options . getRetryPolicyFactory ( ) , opContext ) ; }

Deletes the specified message from the queue, using the specified request options and operation context.

@param message
A {@link CloudQueueMessage} object that specifies the message to delete.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).

@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@throws StorageException
If a storage service error occurred during the operation.

Deletes the specified message from the queue using the specified request options and operation context .


@DoesServiceRequest
    public void downloadAttributes(QueueRequestOptions options, OperationContext opContext) throws StorageException {
        if (opContext == null) {
            opContext = new OperationContext();
        }

        opContext.initialize();
        options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

        ExecutionEngine.executeWithRetry(this.queueServiceClient, this, this.downloadAttributesImpl(options),
                options.getRetryPolicyFactory(), opContext);
    }

@ DoesServiceRequest public void downloadAttributes ( QueueRequestOptions options , OperationContext opContext ) throws StorageException { if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = QueueRequestOptions . populateAndApplyDefaults ( options , this . queueServiceClient ) ; ExecutionEngine . executeWithRetry ( this . queueServiceClient , this , this . downloadAttributesImpl ( options ) , options . getRetryPolicyFactory ( ) , opContext ) ; }

Downloads the queue's metadata and approximate message count value, using the specified request options and
operation context.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueue}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@throws StorageException
If a storage service error occurred during the operation.

Downloads the queue s metadata and approximate message count value using the specified request options and operation context .


@DoesServiceRequest
    public boolean exists(QueueRequestOptions options, OperationContext opContext) throws StorageException {
        return this.exists(false, options, opContext);
    }

@ DoesServiceRequest public boolean exists ( QueueRequestOptions options , OperationContext opContext ) throws StorageException { return this . exists ( false , options , opContext ) ; }

Returns a value that indicates whether the queue existse, using the specified request options and operation
context.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@return true if the queue exists in the storage service, otherwise false.

@throws StorageException
If a storage service error occurred during the operation.

Returns a value that indicates whether the queue existse using the specified request options and operation context .


@DoesServiceRequest
    public CloudQueueMessage peekMessage(final QueueRequestOptions options, final OperationContext opContext)
            throws StorageException {
        return getFirstOrNull(this.peekMessages(1, null /* options */, null /* opContext */));
    }

@
DoesServiceRequest
public
CloudQueueMessage
peekMessage
(
final
QueueRequestOptions
options
,
final
OperationContext
opContext
)
throws
StorageException
{
return
getFirstOrNull
(
this
.
peekMessages
(
1
,
/* options */
,
/* opContext */
)
)
;
}

Peeks a message from the queue, using the specified request options and operation context. A peek request
retrieves a message from the front of the queue without changing its visibility.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@return An {@link CloudQueueMessage} object that represents the requested message from the queue.

@throws StorageException
If a storage service error occurred during the operation.

Peeks a message from the queue using the specified request options and operation context . A peek request retrieves a message from the front of the queue without changing its visibility .


@DoesServiceRequest
    public Iterable<CloudQueueMessage> peekMessages(final int numberOfMessages) throws StorageException {
        return this.peekMessages(numberOfMessages, null /* options */, null /* opContext */);
    }

@
DoesServiceRequest
public
Iterable
<
CloudQueueMessage
>
peekMessages
(
final
int
numberOfMessages
)
throws
StorageException
{
return
this
.
peekMessages
(
numberOfMessages
,
/* options */
,
/* opContext */
)
;
}

Peeks a specified number of messages from the queue. A peek request retrieves messages from the front of the
queue without changing their visibility.

@param numberOfMessages
The number of messages to retrieve.

@return An enumerable collection of {@link CloudQueueMessage} objects that represents the requested messages from
the queue.

@throws StorageException
If a storage service error occurred during the operation.

Peeks a specified number of messages from the queue . A peek request retrieves messages from the front of the queue without changing their visibility .


@DoesServiceRequest
    public Iterable<CloudQueueMessage> peekMessages(final int numberOfMessages, QueueRequestOptions options,
            OperationContext opContext) throws StorageException {
        Utility.assertInBounds("numberOfMessages", numberOfMessages, 1, QueueConstants.MAX_NUMBER_OF_MESSAGES_TO_PEEK);

        if (opContext == null) {
            opContext = new OperationContext();
        }

        opContext.initialize();
        options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

        return ExecutionEngine.executeWithRetry(this.queueServiceClient, this,
                this.peekMessagesImpl(numberOfMessages, options), options.getRetryPolicyFactory(), opContext);
    }

@ DoesServiceRequest public Iterable < CloudQueueMessage > peekMessages ( final int numberOfMessages , QueueRequestOptions options , OperationContext opContext ) throws StorageException { Utility . assertInBounds ( "numberOfMessages" , numberOfMessages , 1 , QueueConstants . MAX_NUMBER_OF_MESSAGES_TO_PEEK ) ; if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = QueueRequestOptions . populateAndApplyDefaults ( options , this . queueServiceClient ) ; return ExecutionEngine . executeWithRetry ( this . queueServiceClient , this , this . peekMessagesImpl ( numberOfMessages , options ) , options . getRetryPolicyFactory ( ) , opContext ) ; }

Peeks a set of messages from the queue, using the specified request options and operation context. A peek request
retrieves messages from the front of the queue without changing their visibility.

@param numberOfMessages
The number of messages to retrieve.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@return An enumerable collection of {@link CloudQueueMessage} objects that represents the requested messages from
the queue.

@throws StorageException
If a storage service error occurred during the operation.

Peeks a set of messages from the queue using the specified request options and operation context . A peek request retrieves messages from the front of the queue without changing their visibility .


@DoesServiceRequest
    public CloudQueueMessage retrieveMessage(final int visibilityTimeoutInSeconds, final QueueRequestOptions options,
            final OperationContext opContext) throws StorageException {
        return getFirstOrNull(this.retrieveMessages(1, visibilityTimeoutInSeconds, options, opContext));
    }

@ DoesServiceRequest public CloudQueueMessage retrieveMessage ( final int visibilityTimeoutInSeconds , final QueueRequestOptions options , final OperationContext opContext ) throws StorageException { return getFirstOrNull ( this . retrieveMessages ( 1 , visibilityTimeoutInSeconds , options , opContext ) ) ; }

Retrieves a message from the front of the queue, using the specified request options and operation context. This
operation marks the retrieved message as invisible in the queue for the specified visibility timeout period.

@param visibilityTimeoutInSeconds
Specifies the visibility timeout for the message, in seconds.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@return An {@link CloudQueueMessage} object that represents a message in this queue.

@throws StorageException
If a storage service error occurred during the operation.

Retrieves a message from the front of the queue using the specified request options and operation context . This operation marks the retrieved message as invisible in the queue for the specified visibility timeout period .


@DoesServiceRequest
    public Iterable<CloudQueueMessage> retrieveMessages(final int numberOfMessages) throws StorageException {
        return this.retrieveMessages(numberOfMessages, QueueConstants.DEFAULT_VISIBILITY_MESSAGE_TIMEOUT_IN_SECONDS,
                null /* options */, null /* opContext */);
    }

Retrieves the specified number of messages from the front of the queue using the default request options. This
operation marks the retrieved messages as invisible in the queue for the default visibility timeout period.

@param numberOfMessages
The number of messages to retrieve.

@return An enumerable collection of {@link CloudQueueMessage} objects that represents the retrieved messages from
the queue.

@throws StorageException
If a storage service error occurred during the operation.

Retrieves the specified number of messages from the front of the queue using the default request options . This operation marks the retrieved messages as invisible in the queue for the default visibility timeout period .


@DoesServiceRequest
    public Iterable<CloudQueueMessage> retrieveMessages(final int numberOfMessages,
            final int visibilityTimeoutInSeconds, QueueRequestOptions options, OperationContext opContext)
            throws StorageException {
        Utility.assertInBounds("numberOfMessages", numberOfMessages, 1, QueueConstants.MAX_NUMBER_OF_MESSAGES_TO_PEEK);
        Utility.assertInBounds("visibilityTimeoutInSeconds", visibilityTimeoutInSeconds, 0,
                QueueConstants.MAX_TIME_TO_LIVE_IN_SECONDS);

        if (opContext == null) {
            opContext = new OperationContext();
        }

        opContext.initialize();
        options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

        return ExecutionEngine.executeWithRetry(this.queueServiceClient, this,
                this.retrieveMessagesImpl(numberOfMessages, visibilityTimeoutInSeconds, options),
                options.getRetryPolicyFactory(), opContext);
    }

@ DoesServiceRequest public Iterable < CloudQueueMessage > retrieveMessages ( final int numberOfMessages , final int visibilityTimeoutInSeconds , QueueRequestOptions options , OperationContext opContext ) throws StorageException { Utility . assertInBounds ( "numberOfMessages" , numberOfMessages , 1 , QueueConstants . MAX_NUMBER_OF_MESSAGES_TO_PEEK ) ; Utility . assertInBounds ( "visibilityTimeoutInSeconds" , visibilityTimeoutInSeconds , 0 , QueueConstants . MAX_TIME_TO_LIVE_IN_SECONDS ) ; if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = QueueRequestOptions . populateAndApplyDefaults ( options , this . queueServiceClient ) ; return ExecutionEngine . executeWithRetry ( this . queueServiceClient , this , this . retrieveMessagesImpl ( numberOfMessages , visibilityTimeoutInSeconds , options ) , options . getRetryPolicyFactory ( ) , opContext ) ; }

Retrieves the specified number of messages from the front of the queue using the specified request options and
operation context. This operation marks the retrieved messages as invisible in the queue for the default
visibility timeout period.

@param numberOfMessages
The number of messages to retrieve.

@param visibilityTimeoutInSeconds
Specifies the visibility timeout for the retrieved messages, in seconds.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@return An enumerable collection of {@link CloudQueueMessage} objects that represents the messages retrieved from
the queue.

@throws StorageException
If a storage service error occurred during the operation.

Retrieves the specified number of messages from the front of the queue using the specified request options and operation context . This operation marks the retrieved messages as invisible in the queue for the default visibility timeout period .


public void updateMessage(final CloudQueueMessage message, final int visibilityTimeoutInSeconds)
            throws StorageException {
        this.updateMessage(message, visibilityTimeoutInSeconds, EnumSet.of(MessageUpdateFields.VISIBILITY),
                null /* options */, null /* opContext */);
    }

public
void
updateMessage
(
final
CloudQueueMessage
message
,
final
int
visibilityTimeoutInSeconds
)
throws
StorageException
{
this
.
updateMessage
(
message
,
visibilityTimeoutInSeconds
,
EnumSet
.
of
(
MessageUpdateFields
.
VISIBILITY
)
,
/* options */
,
/* opContext */
)
;
}

Updates the specified message in the queue with a new visibility timeout value in seconds.

@param message
The {@link CloudQueueMessage} to update in the queue.

@param visibilityTimeoutInSeconds
Specifies the new visibility timeout for the message, in seconds.

@throws StorageException
If a storage service error occurred during the operation.

Updates the specified message in the queue with a new visibility timeout value in seconds .


@DoesServiceRequest
    public void updateMessage(final CloudQueueMessage message, final int visibilityTimeoutInSeconds,
            final EnumSet<MessageUpdateFields> messageUpdateFields, QueueRequestOptions options,
            OperationContext opContext) throws StorageException {
        Utility.assertNotNull("message", message);
        Utility.assertNotNullOrEmpty("messageId", message.getId());
        Utility.assertNotNullOrEmpty("popReceipt", message.getPopReceipt());

        Utility.assertInBounds("visibilityTimeoutInSeconds", visibilityTimeoutInSeconds, 0,
                QueueConstants.MAX_TIME_TO_LIVE_IN_SECONDS);

        if (opContext == null) {
            opContext = new OperationContext();
        }

        opContext.initialize();
        options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

        ExecutionEngine.executeWithRetry(this.queueServiceClient, this,
                this.updateMessageImpl(message, visibilityTimeoutInSeconds, messageUpdateFields, options),
                options.getRetryPolicyFactory(), opContext);
    }

@ DoesServiceRequest public void updateMessage ( final CloudQueueMessage message , final int visibilityTimeoutInSeconds , final EnumSet < MessageUpdateFields > messageUpdateFields , QueueRequestOptions options , OperationContext opContext ) throws StorageException { Utility . assertNotNull ( "message" , message ) ; Utility . assertNotNullOrEmpty ( "messageId" , message . getId ( ) ) ; Utility . assertNotNullOrEmpty ( "popReceipt" , message . getPopReceipt ( ) ) ; Utility . assertInBounds ( "visibilityTimeoutInSeconds" , visibilityTimeoutInSeconds , 0 , QueueConstants . MAX_TIME_TO_LIVE_IN_SECONDS ) ; if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = QueueRequestOptions . populateAndApplyDefaults ( options , this . queueServiceClient ) ; ExecutionEngine . executeWithRetry ( this . queueServiceClient , this , this . updateMessageImpl ( message , visibilityTimeoutInSeconds , messageUpdateFields , options ) , options . getRetryPolicyFactory ( ) , opContext ) ; }

Updates a message in the queue, using the specified request options and operation context.

@param message
The {@link CloudQueueMessage} to update in the queue.

@param visibilityTimeoutInSeconds
Specifies the new visibility timeout for the message, in seconds.

@param messageUpdateFields
An EnumSet of {@link MessageUpdateFields} values that specifies which parts of the
message are to be updated.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).

@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@throws StorageException
If a storage service error occurred during the operation.

Updates a message in the queue using the specified request options and operation context .


@DoesServiceRequest
    public void uploadPermissions(final QueuePermissions permissions, QueueRequestOptions options,
            OperationContext opContext) throws StorageException {
        if (opContext == null) {
            opContext = new OperationContext();
        }

        opContext.initialize();
        options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

        ExecutionEngine.executeWithRetry(this.queueServiceClient, this,
                this.uploadPermissionsImpl(permissions, options), options.getRetryPolicyFactory(), opContext);
    }

@ DoesServiceRequest public void uploadPermissions ( final QueuePermissions permissions , QueueRequestOptions options , OperationContext opContext ) throws StorageException { if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = QueueRequestOptions . populateAndApplyDefaults ( options , this . queueServiceClient ) ; ExecutionEngine . executeWithRetry ( this . queueServiceClient , this , this . uploadPermissionsImpl ( permissions , options ) , options . getRetryPolicyFactory ( ) , opContext ) ; }

Uploads the queue's permissions using the specified request options and operation context.

@param permissions
A {@link QueuePermissions} object that represents the permissions to upload.
@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@throws StorageException
If a storage service error occurred.

Uploads the queue s permissions using the specified request options and operation context .


@DoesServiceRequest
    public QueuePermissions downloadPermissions(QueueRequestOptions options, OperationContext opContext)
            throws StorageException {
        if (opContext == null) {
            opContext = new OperationContext();
        }

        opContext.initialize();
        options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

        return ExecutionEngine.executeWithRetry(this.queueServiceClient, this, this.downloadPermissionsImpl(options),
                options.getRetryPolicyFactory(), opContext);
    }

@ DoesServiceRequest public QueuePermissions downloadPermissions ( QueueRequestOptions options , OperationContext opContext ) throws StorageException { if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = QueueRequestOptions . populateAndApplyDefaults ( options , this . queueServiceClient ) ; return ExecutionEngine . executeWithRetry ( this . queueServiceClient , this , this . downloadPermissionsImpl ( options ) , options . getRetryPolicyFactory ( ) , opContext ) ; }

Downloads the permissions settings for the queue using the specified request options and operation context.

@param options
A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
null will use the default request options from the associated service client (
{@link CloudQueueClient}).
@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@return A {@link QueuePermissions} object that represents the container's permissions.

@throws StorageException
If a storage service error occurred.

Downloads the permissions settings for the queue using the specified request options and operation context .


private final StorageUri getTransformedAddress(final OperationContext opContext) throws URISyntaxException,
            StorageException {
        return this.queueServiceClient.getCredentials().transformUri(this.getStorageUri(), opContext);
    }

private final StorageUri getTransformedAddress ( final OperationContext opContext ) throws URISyntaxException , StorageException { return this . queueServiceClient . getCredentials ( ) . transformUri ( this . getStorageUri ( ) , opContext ) ; }

Returns the transformed URI for the resource if the given credentials require transformation.

@param opContext
An {@link OperationContext} object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.

@return A java.net.URI object that represents the transformed URI.

@throws IllegalArgumentException
If the URI is not absolute.
@throws StorageException
If a storage service error occurred.
@throws URISyntaxException
If the resource URI is invalid.

Returns the transformed URI for the resource if the given credentials require transformation .


public CloudTable getHourMetricsTable(StorageService service, StorageLocation location) throws URISyntaxException,
            StorageException {
        Utility.assertNotNull("service", service);
        if (location == null) {
            location = StorageLocation.PRIMARY;
        }

        switch (service) {
            case BLOB:
                if (location == StorageLocation.PRIMARY) {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_HOUR_PRIMARY_TRANSACTIONS_BLOB);
                }
                else {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_HOUR_SECONDARY_TRANSACTIONS_BLOB);
                }

            case FILE:
                if (location == StorageLocation.PRIMARY) {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_HOUR_PRIMARY_TRANSACTIONS_FILE);
                }
                else {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_HOUR_SECONDARY_TRANSACTIONS_FILE);
                }

            case QUEUE:
                if (location == StorageLocation.PRIMARY) {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_HOUR_PRIMARY_TRANSACTIONS_QUEUE);
                }
                else {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_HOUR_SECONDARY_TRANSACTIONS_QUEUE);
                }

            case TABLE:
                if (location == StorageLocation.PRIMARY) {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_HOUR_PRIMARY_TRANSACTIONS_TABLE);
                }
                else {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_HOUR_SECONDARY_TRANSACTIONS_TABLE);
                }

            default:
                throw new IllegalArgumentException(SR.INVALID_STORAGE_SERVICE);
        }
    }

Gets the hour metrics table for a specific storage service.

@param service
A {@link StorageService} enumeration value that indicates which storage service to use.
@param location
A {@link StorageLocation} enumeration value that indicates which storage location to use.
@return
The {@link CloudTable} object for the storage service.
@throws URISyntaxException
@throws StorageException

Gets the hour metrics table for a specific storage service .


public CloudTable getMinuteMetricsTable(StorageService service, StorageLocation location)
            throws URISyntaxException, StorageException {
        Utility.assertNotNull("service", service);
        if (location == null) {
            location = StorageLocation.PRIMARY;
        }

        switch (service) {
            case BLOB:
                if (location == StorageLocation.PRIMARY) {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_MINUTE_PRIMARY_TRANSACTIONS_BLOB);
                }
                else {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_MINUTE_SECONDARY_TRANSACTIONS_BLOB);
                }
            case FILE:
                if (location == StorageLocation.PRIMARY) {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_MINUTE_PRIMARY_TRANSACTIONS_FILE);
                }
                else {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_MINUTE_SECONDARY_TRANSACTIONS_FILE);
                }
            case QUEUE:
                if (location == StorageLocation.PRIMARY) {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_MINUTE_PRIMARY_TRANSACTIONS_QUEUE);
                }
                else {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_MINUTE_SECONDARY_TRANSACTIONS_QUEUE);
                }
            case TABLE:
                if (location == StorageLocation.PRIMARY) {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_MINUTE_PRIMARY_TRANSACTIONS_TABLE);
                }
                else {
                    return this.tableClient.getTableReference(
                            Constants.AnalyticsConstants.METRICS_MINUTE_SECONDARY_TRANSACTIONS_TABLE);
                }
            default:
                throw new IllegalArgumentException(SR.INVALID_STORAGE_SERVICE);
        }
    }

Gets the minute metrics table for a specific storage service.

@param service
A {@link StorageService} enumeration value that indicates which storage service to use.
@param location
A {@link StorageLocation} enumeration value that indicates which storage location to use.
@return
The CloudTable object for the storage service.
@throws URISyntaxException
@throws StorageException

Gets the minute metrics table for a specific storage service .


public final byte[] getMessageContentAsByte() throws StorageException {
        if (Utility.isNullOrEmpty(this.messageContent)) {
            return new byte[0];
        }

        if (this.messageType == QueueMessageType.RAW_STRING) {
            try {
                return this.messageContent.getBytes(Constants.UTF8_CHARSET);
            }
            catch (final UnsupportedEncodingException e) {
                throw Utility.generateNewUnexpectedStorageException(e);
            }
        }
        else {
            return Base64.decode(this.messageContent);
        }
    }

public final byte [ ] getMessageContentAsByte ( ) throws StorageException { if ( Utility . isNullOrEmpty ( this . messageContent ) ) { return new byte [ 0 ] ; } if ( this . messageType == QueueMessageType . RAW_STRING ) { try { return this . messageContent . getBytes ( Constants . UTF8_CHARSET ) ; } catch ( final UnsupportedEncodingException e ) { throw Utility . generateNewUnexpectedStorageException ( e ) ; } } else { return Base64 . decode ( this . messageContent ) ; } }

Gets the content of the message as a byte array.

@return A byte array which contains the content of the message.

@throws StorageException
If a storage service error occurred.

Gets the content of the message as a byte array .


public final String getMessageContentAsString() throws StorageException {
        if (this.messageType == QueueMessageType.RAW_STRING) {
            return this.messageContent;
        }
        else {
            if (Utility.isNullOrEmpty(this.messageContent)) {
                return null;
            }

            try {
                return new String(Base64.decode(this.messageContent), Constants.UTF8_CHARSET);
            }
            catch (final UnsupportedEncodingException e) {
                throw Utility.generateNewUnexpectedStorageException(e);
            }
        }
    }

public final String getMessageContentAsString ( ) throws StorageException { if ( this . messageType == QueueMessageType . RAW_STRING ) { return this . messageContent ; } else { if ( Utility . isNullOrEmpty ( this . messageContent ) ) { return null ; } try { return new String ( Base64 . decode ( this . messageContent ) , Constants . UTF8_CHARSET ) ; } catch ( final UnsupportedEncodingException e ) { throw Utility . generateNewUnexpectedStorageException ( e ) ; } } }

Gets the content of the message as a string.

@return A String which contains the content of the message.

@throws StorageException
If a storage service error occurred.

Gets the content of the message as a string .


public static ListResponse<ListFileItem> getFileAndDirectoryList(final InputStream stream,
            final CloudFileDirectory directory) throws ParserConfigurationException, SAXException, IOException {
        SAXParser saxParser = Utility.getSAXParser();
        FileListHandler handler = new FileListHandler(directory);
        saxParser.parse(stream, handler);

        return handler.response;
    }

public static ListResponse < ListFileItem > getFileAndDirectoryList ( final InputStream stream , final CloudFileDirectory directory ) throws ParserConfigurationException , SAXException , IOException { SAXParser saxParser = Utility . getSAXParser ( ) ; FileListHandler handler = new FileListHandler ( directory ) ; saxParser . parse ( stream , handler ) ; return handler . response ; }

Parse and return the response.

@param stream
@param directory
@return
@throws ParserConfigurationException
@throws SAXException
@throws IOException


private static void applyContinuationToQueryBuilder(final UriQueryBuilder builder,
            final ResultContinuation continuationToken) throws StorageException {
        if (continuationToken != null) {
            if (continuationToken.getNextPartitionKey() != null) {
                builder.add(TableConstants.TABLE_SERVICE_NEXT_PARTITION_KEY, continuationToken.getNextPartitionKey());
            }

            if (continuationToken.getNextRowKey() != null) {
                builder.add(TableConstants.TABLE_SERVICE_NEXT_ROW_KEY, continuationToken.getNextRowKey());
            }

            if (continuationToken.getNextTableName() != null) {
                builder.add(TableConstants.TABLE_SERVICE_NEXT_TABLE_NAME, continuationToken.getNextTableName());
            }
        }
    }

private static void applyContinuationToQueryBuilder ( final UriQueryBuilder builder , final ResultContinuation continuationToken ) throws StorageException { if ( continuationToken != null ) { if ( continuationToken . getNextPartitionKey ( ) != null ) { builder . add ( TableConstants . TABLE_SERVICE_NEXT_PARTITION_KEY , continuationToken . getNextPartitionKey ( ) ) ; } if ( continuationToken . getNextRowKey ( ) != null ) { builder . add ( TableConstants . TABLE_SERVICE_NEXT_ROW_KEY , continuationToken . getNextRowKey ( ) ) ; } if ( continuationToken . getNextTableName ( ) != null ) { builder . add ( TableConstants . TABLE_SERVICE_NEXT_TABLE_NAME , continuationToken . getNextTableName ( ) ) ; } } }

Reserved for internal use. Adds continuation token values to the specified query builder, if set.

@param builder
The {@link UriQueryBuilder} object to apply the continuation token properties to.
@param continuationToken
The {@link ResultContinuation} object containing the continuation token values to apply to the query
builder. Specify null if no continuation token values are set.

@throws StorageException
if an error occurs in accessing the query builder or continuation token.

Reserved for internal use . Adds continuation token values to the specified query builder if set .


public static HttpURLConnection merge(final URI rootUri, final TableRequestOptions tableOptions,
            final UriQueryBuilder queryBuilder, final OperationContext opContext, final String tableName,
            final String identity, final String eTag) throws IOException, URISyntaxException, StorageException {
        final HttpURLConnection retConnection = coreCreate(rootUri, tableOptions, queryBuilder, opContext, tableName,
                eTag, identity, "POST");
        retConnection.setRequestProperty(TableConstants.HeaderConstants.X_HTTP_METHOD, "MERGE");
        retConnection.setDoOutput(true);
        return retConnection;
    }

public static HttpURLConnection merge ( final URI rootUri , final TableRequestOptions tableOptions , final UriQueryBuilder queryBuilder , final OperationContext opContext , final String tableName , final String identity , final String eTag ) throws IOException , URISyntaxException , StorageException { final HttpURLConnection retConnection = coreCreate ( rootUri , tableOptions , queryBuilder , opContext , tableName , eTag , identity , "POST" ) ; retConnection . setRequestProperty ( TableConstants . HeaderConstants . X_HTTP_METHOD , "MERGE" ) ; retConnection . setDoOutput ( true ) ; return retConnection ; }

Reserved for internal use. Constructs an HttpURLConnection to perform a merge operation.

@param rootUri
A java.net.URI containing an absolute URI to the resource.
@param tableOptions
A {@link TableRequestOptions} object that specifies execution options such as retry policy and timeout
settings for the operation. Specify null to use the request options specified on the
{@link CloudTableClient}.
@param queryBuilder
The {@link UriQueryBuilder} for the operation.
@param opContext
An {@link OperationContext} object for tracking the current operation. Specify null to
safely ignore operation context.
@param tableName
The name of the table.
@param identity
The identity of the entity. The resulting request will be formatted as /tableName(identity) if not
null or empty.
@param eTag
The etag of the entity.
@return
An HttpURLConnection to use to perform the operation.

@throws IOException
if there is an error opening the connection.
@throws URISyntaxException
if the resource URI is invalid.
@throws StorageException
if a storage service error occurred during the operation.

Reserved for internal use . Constructs an HttpURLConnection to perform a merge operation .


public static HttpURLConnection query(final URI rootUri, final TableRequestOptions tableOptions,
            UriQueryBuilder queryBuilder, final OperationContext opContext, final String tableName,
            final String identity, final ResultContinuation continuationToken) throws IOException, URISyntaxException,
            StorageException {
        if (queryBuilder == null) {
            queryBuilder = new UriQueryBuilder();
        }

        applyContinuationToQueryBuilder(queryBuilder, continuationToken);
        final HttpURLConnection retConnection = coreCreate(rootUri, tableOptions, queryBuilder, opContext, tableName,
                null, identity, "GET");

        return retConnection;
    }

public static HttpURLConnection query ( final URI rootUri , final TableRequestOptions tableOptions , UriQueryBuilder queryBuilder , final OperationContext opContext , final String tableName , final String identity , final ResultContinuation continuationToken ) throws IOException , URISyntaxException , StorageException { if ( queryBuilder == null ) { queryBuilder = new UriQueryBuilder ( ) ; } applyContinuationToQueryBuilder ( queryBuilder , continuationToken ) ; final HttpURLConnection retConnection = coreCreate ( rootUri , tableOptions , queryBuilder , opContext , tableName , null , identity , "GET" ) ; return retConnection ; }

Reserved for internal use. Constructs an HttpURLConnection to perform a single entity query operation.

@param rootUri
A java.net.URI containing an absolute URI to the resource.
@param tableOptions
A {@link TableRequestOptions} object that specifies execution options such as retry policy and timeout
settings for the operation. Specify null to use the request options specified on the
{@link CloudTableClient}.
@param queryBuilder
The {@link UriQueryBuilder} for the operation.
@param opContext
An {@link OperationContext} object for tracking the current operation. Specify null to
safely ignore operation context.
@param tableName
The name of the table.
@param identity
The identity of the entity. The resulting request will be formatted as /tableName(identity) if not
null or empty.
@return
An HttpURLConnection to use to perform the operation.

@throws IOException
if there is an error opening the connection.
@throws URISyntaxException
if the resource URI is invalid.
@throws StorageException
if a storage service error occurred during the operation.

Reserved for internal use . Constructs an HttpURLConnection to perform a single entity query operation .