microsoft-azure-storage/src/com/microsoft/azure/storage/core/SharedAccessSignatureHelper.java
private static UriQueryBuilder generateSharedAccessSignatureHelper(
            final SharedAccessPolicy policy, final String startPartitionKey, final String startRowKey,
            final String endPartitionKey, final String endRowKey, final String accessPolicyIdentifier,
            final String resourceType, final IPRange ipRange, final SharedAccessProtocols protocols,
            final String tableName, final String signature, final SharedAccessHeaders headers)
            throws StorageException {
        
        Utility.assertNotNull("signature", signature);

        String permissions = null;
        Date startTime = null;
        Date expiryTime = null;
        if (policy != null) {
            permissions = policy.permissionsToString();
            startTime = policy.getSharedAccessStartTime();
            expiryTime = policy.getSharedAccessExpiryTime();
        }

        final UriQueryBuilder builder = new UriQueryBuilder();

        builder.add(Constants.QueryConstants.SIGNED_VERSION, Constants.HeaderConstants.TARGET_STORAGE_VERSION);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_PERMISSIONS, permissions);

        final String startString = Utility.getUTCTimeOrEmpty(startTime);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_START, startString);

        final String stopString = Utility.getUTCTimeOrEmpty(expiryTime);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_EXPIRY, stopString);

        addIfNotNullOrEmpty(builder, Constants.QueryConstants.START_PARTITION_KEY, startPartitionKey);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.START_ROW_KEY, startRowKey);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.END_PARTITION_KEY, endPartitionKey);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.END_ROW_KEY, endRowKey);

        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_IDENTIFIER, accessPolicyIdentifier);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_RESOURCE, resourceType);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_IP, ipRange != null ? ipRange.toString() : null);
        addIfNotNullOrEmpty(
                builder, Constants.QueryConstants.SIGNED_PROTOCOLS, protocols != null ? protocols.toString() : null);

        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SAS_TABLE_NAME, tableName);

        if (headers != null) {
            addIfNotNullOrEmpty(builder, Constants.QueryConstants.CACHE_CONTROL, headers.getCacheControl());
            addIfNotNullOrEmpty(builder, Constants.QueryConstants.CONTENT_TYPE, headers.getContentType());
            addIfNotNullOrEmpty(builder, Constants.QueryConstants.CONTENT_ENCODING, headers.getContentEncoding());
            addIfNotNullOrEmpty(builder, Constants.QueryConstants.CONTENT_LANGUAGE, headers.getContentLanguage());
            addIfNotNullOrEmpty(builder, Constants.QueryConstants.CONTENT_DISPOSITION, headers.getContentDisposition());
        }

        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNATURE, signature);

        return builder;
    }
private static UriQueryBuilder generateSharedAccessSignatureHelper(
            final SharedAccessPolicy policy, final String startPartitionKey, final String startRowKey,
            final String endPartitionKey, final String endRowKey, final String accessPolicyIdentifier,
            final String resourceType, final IPRange ipRange, final SharedAccessProtocols protocols,
            final String tableName, final String signature, final SharedAccessHeaders headers)
            throws StorageException {
        
        Utility.assertNotNull("signature", signature);

        String permissions = null;
        Date startTime = null;
        Date expiryTime = null;
        if (policy != null) {
            permissions = policy.permissionsToString();
            startTime = policy.getSharedAccessStartTime();
            expiryTime = policy.getSharedAccessExpiryTime();
        }

        final UriQueryBuilder builder = new UriQueryBuilder();

        builder.add(Constants.QueryConstants.SIGNED_VERSION, Constants.HeaderConstants.TARGET_STORAGE_VERSION);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_PERMISSIONS, permissions);

        final String startString = Utility.getUTCTimeOrEmpty(startTime);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_START, startString);

        final String stopString = Utility.getUTCTimeOrEmpty(expiryTime);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_EXPIRY, stopString);

        addIfNotNullOrEmpty(builder, Constants.QueryConstants.START_PARTITION_KEY, startPartitionKey);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.START_ROW_KEY, startRowKey);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.END_PARTITION_KEY, endPartitionKey);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.END_ROW_KEY, endRowKey);

        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_IDENTIFIER, accessPolicyIdentifier);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_RESOURCE, resourceType);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_IP, ipRange != null ? ipRange.toString() : null);
        addIfNotNullOrEmpty(
                builder, Constants.QueryConstants.SIGNED_PROTOCOLS, protocols != null ? protocols.toString() : null);

        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SAS_TABLE_NAME, tableName);

        if (headers != null) {
            addIfNotNullOrEmpty(builder, Constants.QueryConstants.CACHE_CONTROL, headers.getCacheControl());
            addIfNotNullOrEmpty(builder, Constants.QueryConstants.CONTENT_TYPE, headers.getContentType());
            addIfNotNullOrEmpty(builder, Constants.QueryConstants.CONTENT_ENCODING, headers.getContentEncoding());
            addIfNotNullOrEmpty(builder, Constants.QueryConstants.CONTENT_LANGUAGE, headers.getContentLanguage());
            addIfNotNullOrEmpty(builder, Constants.QueryConstants.CONTENT_DISPOSITION, headers.getContentDisposition());
        }

        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNATURE, signature);

        return builder;
    }
private static UriQueryBuilder generateSharedAccessSignatureHelper ( final SharedAccessPolicy policy , final String startPartitionKey , final String startRowKey , final String endPartitionKey , final String endRowKey , final String accessPolicyIdentifier , final String resourceType , final IPRange ipRange , final SharedAccessProtocols protocols , final String tableName , final String signature , final SharedAccessHeaders headers ) throws StorageException { Utility . assertNotNull ( "signature" , signature ) ; String permissions = null ; Date startTime = null ; Date expiryTime = null ; if ( policy != null ) { permissions = policy . permissionsToString ( ) ; startTime = policy . getSharedAccessStartTime ( ) ; expiryTime = policy . getSharedAccessExpiryTime ( ) ; } final UriQueryBuilder builder = new UriQueryBuilder ( ) ; builder . add ( Constants . QueryConstants . SIGNED_VERSION , Constants . HeaderConstants . TARGET_STORAGE_VERSION ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_PERMISSIONS , permissions ) ; final String startString = Utility . getUTCTimeOrEmpty ( startTime ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_START , startString ) ; final String stopString = Utility . getUTCTimeOrEmpty ( expiryTime ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_EXPIRY , stopString ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . START_PARTITION_KEY , startPartitionKey ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . START_ROW_KEY , startRowKey ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . END_PARTITION_KEY , endPartitionKey ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . END_ROW_KEY , endRowKey ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_IDENTIFIER , accessPolicyIdentifier ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_RESOURCE , resourceType ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_IP , ipRange != null ? ipRange . toString ( ) : null ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_PROTOCOLS , protocols != null ? protocols . toString ( ) : null ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SAS_TABLE_NAME , tableName ) ; if ( headers != null ) { addIfNotNullOrEmpty ( builder , Constants . QueryConstants . CACHE_CONTROL , headers . getCacheControl ( ) ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . CONTENT_TYPE , headers . getContentType ( ) ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . CONTENT_ENCODING , headers . getContentEncoding ( ) ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . CONTENT_LANGUAGE , headers . getContentLanguage ( ) ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . CONTENT_DISPOSITION , headers . getContentDisposition ( ) ) ; } addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNATURE , signature ) ; return builder ; }
Get the complete query builder for creating the Shared Access Signature query.

@param policy
A {@link SharedAccessPolicy} containing the permissions for the SAS.
@param startPartitionKey
The start partition key for a shared access signature URI.
@param startRowKey
The start row key for a shared access signature URI.
@param endPartitionKey
The end partition key for a shared access signature URI.
@param endRowKey
The end row key for a shared access signature URI.
@param accessPolicyIdentifier
An optional identifier for the policy.
@param resourceType
The resource type for a shared access signature URI.
@param ipRange
The range of IP addresses for the shared access signature.
@param protocols
The Internet protocols for the shared access signature.
@param tableName
The table name.
@param signature
The signature hash.
@param headers
Optional blob or file headers.

@return The finished query builder.
@throws StorageException
An exception representing any error which occurred during the operation.
Get the complete query builder for creating the Shared Access Signature query .