Java Code Examples for com.microsoft.azure.storage.AccessCondition#applyConditionToRequest()

The following examples show how to use com.microsoft.azure.storage.AccessCondition#applyConditionToRequest() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileRequest.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a web request to delete the share and all of the directories and files within it. Sign with no length
 * specified.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param fileOptions
 *            A {@link FileRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudFileClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the share.
 * @return a HttpURLConnection configured for the operation.
 * @throws StorageException
 * @throws IllegalArgumentException
 */
public static HttpURLConnection deleteShare(final URI uri, final FileRequestOptions fileOptions,
        final OperationContext opContext, final AccessCondition accessCondition, String snapshotVersion, DeleteShareSnapshotsOption deleteSnapshotsOption) 
                throws IOException, URISyntaxException, StorageException {
    final UriQueryBuilder shareBuilder = getShareUriQueryBuilder();
    FileRequest.addShareSnapshot(shareBuilder, snapshotVersion);
    HttpURLConnection request = BaseRequest.delete(uri, fileOptions, shareBuilder, opContext);
    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    switch (deleteSnapshotsOption) {
    case NONE:
        // nop
        break;
    case INCLUDE_SNAPSHOTS:
        request.setRequestProperty(Constants.HeaderConstants.DELETE_SNAPSHOT_HEADER,
                Constants.HeaderConstants.INCLUDE_SNAPSHOTS_VALUE);
        break;
    default:
        break;
    }

    return request;
}
 
Example 2
Source File: FileRequest.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a web request to abort a copy operation.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param fileOptions
 *            A {@link FileRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudFileClient}.
 * @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.
 * @param accessCondition
 *            The access condition to apply to the request. Only lease conditions are supported for this operation.
 * @param copyId
 *            A <code>String</code> object that identifying the copy operation.
 * @return a <code>HttpURLConnection</code> configured for the operation.
 * @throws StorageException
 *             An exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 * @throws IOException
 * @throws URISyntaxException
 */
public static HttpURLConnection abortCopy(final URI uri, final FileRequestOptions fileOptions,
        final OperationContext opContext, final AccessCondition accessCondition, final String copyId)
        throws StorageException, IOException, URISyntaxException {

    final UriQueryBuilder builder = new UriQueryBuilder();

    builder.add(Constants.QueryConstants.COMPONENT, Constants.QueryConstants.COPY);
    builder.add(Constants.QueryConstants.COPY_ID, copyId);

    final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext);

    request.setFixedLengthStreamingMode(0);
    request.setDoOutput(true);
    request.setRequestMethod(Constants.HTTP_PUT);

    request.setRequestProperty(Constants.HeaderConstants.COPY_ACTION_HEADER,
            Constants.HeaderConstants.COPY_ACTION_ABORT);

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    return request;
}
 
Example 3
Source File: BlobRequest.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a HttpURLConnection to Acquire,Release,Break, or Renew a blob/container lease. Sign with 0 length.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param blobOptions
 *            A {@link BlobRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudBlobClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @param action
 *            the LeaseAction to perform
 * @param proposedLeaseId
 *            A <code>String</code> that represents the proposed lease ID for the new lease,
 *            or null if no lease ID is proposed.
 * @param breakPeriodInSeconds
 *            Specifies the amount of time to allow the lease to remain, in seconds.
 *            If null, the break period is the remainder of the current lease, or zero for infinite leases.
 * @param visibilityTimeoutInSeconds
 *            Specifies the the span of time for which to acquire the lease, in seconds.
 *            If null, an infinite lease will be acquired. If not null, this must be greater than zero.
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 */
private static HttpURLConnection lease(final URI uri, final BlobRequestOptions blobOptions,
        final OperationContext opContext, final AccessCondition accessCondition, final LeaseAction action,
        final Integer leaseTimeInSeconds, final String proposedLeaseId, final Integer breakPeriodInSeconds,
        final UriQueryBuilder builder) throws IOException, URISyntaxException, StorageException {
    final HttpURLConnection request = createURLConnection(uri, builder, blobOptions, opContext);

    request.setDoOutput(true);
    request.setRequestMethod(Constants.HTTP_PUT);
    request.setFixedLengthStreamingMode(0);
    request.setRequestProperty(HeaderConstants.LEASE_ACTION_HEADER, action.toString());

    // Lease duration should only be sent for acquire.
    if (action == LeaseAction.ACQUIRE) {
        // Assert lease duration is in bounds
        if (leaseTimeInSeconds != null && leaseTimeInSeconds != -1) {
            Utility.assertInBounds("leaseTimeInSeconds", leaseTimeInSeconds, Constants.LEASE_DURATION_MIN,
                    Constants.LEASE_DURATION_MAX);
        }

        request.setRequestProperty(HeaderConstants.LEASE_DURATION, leaseTimeInSeconds == null ? "-1"
                : leaseTimeInSeconds.toString());
    }

    if (proposedLeaseId != null) {
        request.setRequestProperty(HeaderConstants.PROPOSED_LEASE_ID_HEADER, proposedLeaseId);
    }

    if (breakPeriodInSeconds != null) {
        // Assert lease break period is in bounds
        Utility.assertInBounds("breakPeriodInSeconds", breakPeriodInSeconds, Constants.LEASE_BREAK_PERIOD_MIN,
                Constants.LEASE_BREAK_PERIOD_MAX);
        request.setRequestProperty(HeaderConstants.LEASE_BREAK_PERIOD_HEADER, breakPeriodInSeconds.toString());
    }

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }
    return request;
}
 
Example 4
Source File: BlobRequest.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a HttpURLConnection to upload a block. Sign with length of block data.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param blobOptions
 *            A {@link BlobRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudBlobClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @param blockId
 *            the Base64 ID for the block
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 */
public static HttpURLConnection putBlock(final URI uri, final BlobRequestOptions blobOptions,
        final OperationContext opContext, final AccessCondition accessCondition, final String blockId)
        throws IOException, URISyntaxException, StorageException {
    final UriQueryBuilder builder = new UriQueryBuilder();
    builder.add(Constants.QueryConstants.COMPONENT, BLOCK_QUERY_ELEMENT_NAME);
    builder.add(BLOCK_ID_QUERY_ELEMENT_NAME, blockId);

    final HttpURLConnection request = createURLConnection(uri, builder, blobOptions, opContext);

    request.setDoOutput(true);
    request.setRequestMethod(Constants.HTTP_PUT);

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    return request;
}
 
Example 5
Source File: FileRequest.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a request to copy a file, Sign with 0 length.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param fileOptions
 *            A {@link FileRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudFileClient}.
 * @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.
 * @param source
 *            The canonical path to the source file,
 *            in the form /<account-name>/<share-name>/<directory-path>/<file-name>.
 * @param sourceAccessConditionType
 *            A type of condition to check on the source file.
 * @param sourceAccessConditionValue
 *            The value of the condition to check on the source file
 * @return a HttpURLConnection configured for the operation.
 * @throws StorageException
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 * @throws IOException
 * @throws URISyntaxException
 */
public static HttpURLConnection copyFrom(final URI uri, final FileRequestOptions fileOptions,
        final OperationContext opContext, final AccessCondition sourceAccessCondition,
        final AccessCondition destinationAccessCondition, String source)
        throws StorageException, IOException, URISyntaxException {

    final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, null, opContext);

    request.setFixedLengthStreamingMode(0);
    request.setDoOutput(true);
    request.setRequestMethod(Constants.HTTP_PUT);

    request.setRequestProperty(Constants.HeaderConstants.COPY_SOURCE_HEADER, source);

    if (sourceAccessCondition != null) {
        sourceAccessCondition.applyConditionToRequest(request);
    }

    if (destinationAccessCondition != null) {
        destinationAccessCondition.applyConditionToRequest(request);
    }

    return request;
}
 
Example 6
Source File: FileRequest.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a HttpURLConnection to upload a file range. Sign with file size for update, or 0 for clear.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param fileOptions
 *            A {@link FileRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudFileClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the file.
 * @param range
 *            a {link @FileRange} representing the file range
 * @param operationType
 *            a {link @FileRangeOperationType} enumeration value representing the file range operation type.
 * 
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 */
public static HttpURLConnection putRange(final URI uri, final FileRequestOptions fileOptions,
        final OperationContext opContext, final AccessCondition accessCondition, final FileRange range,
        FileRangeOperationType operationType) throws IOException, URISyntaxException, StorageException {
    final UriQueryBuilder builder = new UriQueryBuilder();
    builder.add(Constants.QueryConstants.COMPONENT, RANGE_QUERY_ELEMENT_NAME);

    final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext);

    request.setDoOutput(true);
    request.setRequestMethod(Constants.HTTP_PUT);

    if (operationType == FileRangeOperationType.CLEAR) {
        request.setFixedLengthStreamingMode(0);
    }

    // Range write is either update or clear; required
    request.setRequestProperty(FileConstants.FILE_RANGE_WRITE, operationType.toString());
    request.setRequestProperty(Constants.HeaderConstants.STORAGE_RANGE_HEADER, range.toString());

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    return request;
}
 
Example 7
Source File: BlobRequest.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a HttpURLConnection to set the blob's properties, Sign with zero length specified.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param blobOptions
 *            A {@link BlobRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudBlobClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @param properties
 *            The properties to upload.
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 */
public static HttpURLConnection setBlobProperties(final URI uri, final BlobRequestOptions blobOptions,
        final OperationContext opContext, final AccessCondition accessCondition, final BlobProperties properties)
        throws IOException, URISyntaxException, StorageException {
    final UriQueryBuilder builder = new UriQueryBuilder();
    builder.add(Constants.QueryConstants.COMPONENT, Constants.QueryConstants.PROPERTIES);

    final HttpURLConnection request = createURLConnection(uri, builder, blobOptions, opContext);

    request.setFixedLengthStreamingMode(0);
    request.setDoOutput(true);
    request.setRequestMethod(Constants.HTTP_PUT);

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    if (properties != null) {
        addProperties(request, properties);
    }

    return request;
}
 
Example 8
Source File: FileRequest.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a HttpURLConnection to return a list of the file's file ranges. Sign with no length specified.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param fileOptions
 *            A {@link FileRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudFileClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the file.
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 */
public static HttpURLConnection getFileRanges(final URI uri, final FileRequestOptions fileOptions,
        final OperationContext opContext, final AccessCondition accessCondition, final String snapshotVersion) throws StorageException,
        IOException, URISyntaxException {

    final UriQueryBuilder builder = new UriQueryBuilder();
    addShareSnapshot(builder, snapshotVersion);
    builder.add(Constants.QueryConstants.COMPONENT, RANGE_LIST_QUERY_ELEMENT_NAME);

    final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext);
    request.setRequestMethod(Constants.HTTP_GET);

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    return request;
}
 
Example 9
Source File: BlobRequest.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a HttpURLConnection to write a blob by specifying the list of block IDs that make up the blob. Sign
 * with length of block list data.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param blobOptions
 *            A {@link BlobRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudBlobClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 */
public static HttpURLConnection putBlockList(final URI uri, final BlobRequestOptions blobOptions,
        final OperationContext opContext, final AccessCondition accessCondition, final BlobProperties properties)
        throws IOException, URISyntaxException, StorageException {

    final UriQueryBuilder builder = new UriQueryBuilder();
    builder.add(Constants.QueryConstants.COMPONENT, BLOCK_LIST_QUERY_ELEMENT_NAME);

    final HttpURLConnection request = createURLConnection(uri, builder, blobOptions, opContext);

    request.setDoOutput(true);
    request.setRequestMethod(Constants.HTTP_PUT);

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    addProperties(request, properties);

    return request;
}
 
Example 10
Source File: BlobRequest.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a web request to commit a block to an append blob.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param blobOptions
 *            A {@link BlobRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudBlobClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 */
public static HttpURLConnection appendBlock(final URI uri, final BlobRequestOptions blobOptions,
        final OperationContext opContext, final AccessCondition accessCondition) 
                throws StorageException, IOException, URISyntaxException
{
    final UriQueryBuilder builder = new UriQueryBuilder();
    builder.add(Constants.QueryConstants.COMPONENT, APPEND_BLOCK_QUERY_ELEMENT_NAME);

    final HttpURLConnection request = createURLConnection(uri, builder, blobOptions, opContext);

    request.setDoOutput(true);
    request.setRequestMethod(Constants.HTTP_PUT);

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
        accessCondition.applyAppendConditionToRequest(request);
    }

    return request;
}
 
Example 11
Source File: BlobRequest.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a HttpURLConnection to upload a blob. Sign with blob length, or -1 for pageblob create.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param blobOptions
 *            A {@link BlobRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudBlobClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @param properties
 *            The properties to set for the blob.
 * @param blobType
 *            The type of the blob.
 * @param pageBlobSize
 *            For a page blob, the size of the blob. This parameter is ignored for block blobs.
 * @param premiumPageBlobTier
 *            A {@link PremiumPageBlobTier} object representing the tier to set.
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 */
public static HttpURLConnection putBlob(final URI uri, final BlobRequestOptions blobOptions,
        final OperationContext opContext, final AccessCondition accessCondition, final BlobProperties properties,
        final BlobType blobType, final long pageBlobSize, final PremiumPageBlobTier premiumPageBlobTier) throws IOException, URISyntaxException, StorageException {
    if (blobType == BlobType.UNSPECIFIED) {
        throw new IllegalArgumentException(SR.BLOB_TYPE_NOT_DEFINED);
    }

    final HttpURLConnection request = createURLConnection(uri, null, blobOptions, opContext);

    request.setDoOutput(true);

    request.setRequestMethod(Constants.HTTP_PUT);

    addProperties(request, properties);

    if (blobType == BlobType.PAGE_BLOB) {
        request.setFixedLengthStreamingMode(0);
        request.setRequestProperty(Constants.HeaderConstants.CONTENT_LENGTH, "0");

        request.setRequestProperty(BlobConstants.BLOB_TYPE_HEADER, BlobConstants.PAGE_BLOB);
        request.setRequestProperty(BlobConstants.SIZE, String.valueOf(pageBlobSize));

        if (premiumPageBlobTier != null)
        {
            request.setRequestProperty(BlobConstants.ACCESS_TIER_HEADER, String.valueOf(premiumPageBlobTier));
        }

        properties.setLength(pageBlobSize);
    }
    else if (blobType == BlobType.BLOCK_BLOB){
        request.setRequestProperty(BlobConstants.BLOB_TYPE_HEADER, BlobConstants.BLOCK_BLOB);
    }
    else if (blobType == BlobType.APPEND_BLOB){
        request.setFixedLengthStreamingMode(0);
        request.setRequestProperty(BlobConstants.BLOB_TYPE_HEADER, BlobConstants.APPEND_BLOB);
        request.setRequestProperty(Constants.HeaderConstants.CONTENT_LENGTH, "0");
    }

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    return request;
}
 
Example 12
Source File: BlobRequest.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a HttpURLConnection to return a list of the PageBlob's page ranges. Sign with no length specified.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param blobOptions
 *            A {@link BlobRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudBlobClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @param snapshotVersion
 *            The snapshot version, if the blob is a snapshot.
 * @param previousSnapshot
 *            A string representing the snapshot timestamp to use as the starting point for the diff. If this
 *            CloudPageBlob represents a snapshot, the previousSnapshot parameter must be prior to the current
 *            snapshot.
 * @param offset
 *            The offset at which to begin returning content.
 * @param count
 *            The number of bytes to return.
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 */
public static HttpURLConnection getPageRangesDiff(final URI uri, final BlobRequestOptions blobOptions,
        final OperationContext opContext, final AccessCondition accessCondition, final String snapshotVersion,
        final String previousSnapshot, final Long offset, final Long count) throws StorageException,
        IOException, URISyntaxException {

    final UriQueryBuilder builder = new UriQueryBuilder();
    builder.add(Constants.QueryConstants.COMPONENT, PAGE_LIST_QUERY_ELEMENT_NAME);
    builder.add(BlobConstants.PREV_SNAPSHOT, previousSnapshot);
    BlobRequest.addSnapshot(builder, snapshotVersion);

    final HttpURLConnection request = createURLConnection(uri, builder, blobOptions, opContext);
    request.setRequestMethod(Constants.HTTP_GET);

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }
    
    addRange(request, offset, count);

    return request;
}
 
Example 13
Source File: FileRequest.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a HttpURLConnection to create a snapshot of the share.
 *
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param fileOptions
 *            A {@link FileRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudFileClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the share.
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 */
public static HttpURLConnection snapshotShare(final URI uri, final FileRequestOptions fileOptions,
                                              final OperationContext opContext, final AccessCondition accessCondition) throws IOException,
        URISyntaxException, StorageException {
    final UriQueryBuilder builder = new UriQueryBuilder();
    builder.add(Constants.QueryConstants.RESOURCETYPE, "share");
    builder.add(Constants.QueryConstants.COMPONENT, Constants.QueryConstants.SNAPSHOT);
    final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext);

    request.setFixedLengthStreamingMode(0);
    request.setDoOutput(true);
    request.setRequestMethod(Constants.HTTP_PUT);

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    return request;
}
 
Example 14
Source File: BlobRequest.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a HttpURLConnection to return a list of the block blobs blocks. Sign with no length specified.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param blobOptions
 *            A {@link BlobRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudBlobClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @param snapshotVersion
 *            The snapshot version, if the blob is a snapshot.
 * @param blockFilter
 *            The types of blocks to include in the list: committed, uncommitted, or both.
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 */
public static HttpURLConnection getBlockList(final URI uri, final BlobRequestOptions blobOptions,
        final OperationContext opContext, final AccessCondition accessCondition, final String snapshotVersion,
        final BlockListingFilter blockFilter) throws StorageException, IOException, URISyntaxException {

    final UriQueryBuilder builder = new UriQueryBuilder();

    builder.add(Constants.QueryConstants.COMPONENT, BLOCK_LIST_QUERY_ELEMENT_NAME);
    builder.add(BLOCK_LIST_TYPE_QUERY_ELEMENT_NAME, blockFilter.toString());
    BlobRequest.addSnapshot(builder, snapshotVersion);

    final HttpURLConnection request = BaseRequest.createURLConnection(uri, blobOptions, builder, opContext);
    request.setRequestMethod(Constants.HTTP_GET);

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    return request;
}
 
Example 15
Source File: FileRequest.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a HttpURLConnection to set the share's properties, signed with zero length specified.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param options
 *            A {@link FileRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudFileClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the file.
 * @param properties
 *            The properties to upload.
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 */
public static HttpURLConnection setShareProperties(final URI uri, final FileRequestOptions options,
        final OperationContext opContext, final AccessCondition accessCondition, final FileShareProperties properties)
        throws IOException, URISyntaxException, StorageException {
    final UriQueryBuilder builder = getShareUriQueryBuilder();
    builder.add(Constants.QueryConstants.COMPONENT, Constants.QueryConstants.PROPERTIES);

    final HttpURLConnection request = BaseRequest.createURLConnection(uri, options, builder, opContext);

    request.setFixedLengthStreamingMode(0);
    request.setDoOutput(true);
    request.setRequestMethod(Constants.HTTP_PUT);

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    if (properties != null) {
        addProperties(request, properties);
    }

    return request;
}
 
Example 16
Source File: BlobRequest.java    From azure-storage-android with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a HttpURLConnection to upload a page. Sign with page length for update, or 0 for clear.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param blobOptions
 *            A {@link BlobRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudBlobClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @param pageRange
 *            A {@link PageRange} object that represents the page range.
 * @param operationType
 *            A {@link PageOperationType} object that represents the page range operation type.
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 */
public static HttpURLConnection putPage(final URI uri, final BlobRequestOptions blobOptions,
        final OperationContext opContext, final AccessCondition accessCondition, final PageRange pageRange,
        final PageOperationType operationType) throws IOException, URISyntaxException, StorageException {
    final UriQueryBuilder builder = new UriQueryBuilder();
    builder.add(Constants.QueryConstants.COMPONENT, PAGE_QUERY_ELEMENT_NAME);

    final HttpURLConnection request = createURLConnection(uri, builder, blobOptions, opContext);

    request.setDoOutput(true);
    request.setRequestMethod(Constants.HTTP_PUT);

    if (operationType == PageOperationType.CLEAR) {
        request.setFixedLengthStreamingMode(0);
    }

    // Page write is either update or clean; required
    request.setRequestProperty(BlobConstants.PAGE_WRITE, operationType.toString());
    request.setRequestProperty(Constants.HeaderConstants.STORAGE_RANGE_HEADER, pageRange.toString());

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
        accessCondition.applySequenceConditionToRequest(request);
    }

    return request;
}
 
Example 17
Source File: BlobRequest.java    From azure-storage-android with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a HttpURLConnection to set the blob's metadata, Sign with 0 length.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param blobOptions
 *            A {@link BlobRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudBlobClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 */
private static HttpURLConnection setMetadata(final URI uri, final BlobRequestOptions blobOptions,
        final OperationContext opContext, final AccessCondition accessCondition, final UriQueryBuilder builder)
        throws IOException, URISyntaxException, StorageException {
    final HttpURLConnection request = BaseRequest.setMetadata(uri, blobOptions, builder, opContext);

    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    return request;
}
 
Example 18
Source File: BlobRequest.java    From azure-storage-android with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a web request to delete the container and all of blobs within it. Sign with no length specified.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param blobOptions
 *            A {@link BlobRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudBlobClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the container.
 * @return a HttpURLConnection configured for the operation.
 * @throws StorageException
 * @throws IllegalArgumentException
 */
public static HttpURLConnection deleteContainer(final URI uri, final BlobRequestOptions blobOptions,
        final OperationContext opContext, final AccessCondition accessCondition) throws IOException,
        URISyntaxException, StorageException {
    final UriQueryBuilder containerBuilder = getContainerUriQueryBuilder();
    HttpURLConnection request = BaseRequest.delete(uri, blobOptions, containerBuilder, opContext);
    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    return request;
}
 
Example 19
Source File: FileRequest.java    From azure-storage-android with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a web request to delete the directory and all of the directories and files within it. Sign with no
 * length
 * specified.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param fileOptions
 *            A {@link FileRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudFileClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the directory.
 * @return a HttpURLConnection configured for the operation.
 * @throws StorageException
 * @throws IllegalArgumentException
 */
public static HttpURLConnection deleteDirectory(final URI uri, final FileRequestOptions fileOptions,
        final OperationContext opContext, final AccessCondition accessCondition) throws IOException,
        URISyntaxException, StorageException {
    final UriQueryBuilder directoryBuilder = getDirectoryUriQueryBuilder();
    HttpURLConnection request = BaseRequest.delete(uri, fileOptions, directoryBuilder, opContext);
    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    return request;
}
 
Example 20
Source File: FileRequest.java    From azure-storage-android with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a HttpURLConnection to delete the file, Sign with no length specified.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param fileOptions
 *            A {@link FileRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudFileClient}.
 * @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.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the file.
 * @return a 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
 *             an exception representing any error which occurred during the operation.
 * @throws IllegalArgumentException
 */
public static HttpURLConnection deleteFile(final URI uri, final FileRequestOptions fileOptions,
        final OperationContext opContext, final AccessCondition accessCondition) throws IOException,
        URISyntaxException, StorageException {
    final UriQueryBuilder builder = new UriQueryBuilder();
    final HttpURLConnection request = BaseRequest.delete(uri, fileOptions, builder, opContext);
    if (accessCondition != null) {
        accessCondition.applyConditionToRequest(request);
    }

    return request;
}