当前位置: 首页>>代码示例>>Java>>正文


Java AccessCondition.generateLeaseCondition方法代码示例

本文整理汇总了Java中com.microsoft.azure.storage.AccessCondition.generateLeaseCondition方法的典型用法代码示例。如果您正苦于以下问题:Java AccessCondition.generateLeaseCondition方法的具体用法?Java AccessCondition.generateLeaseCondition怎么用?Java AccessCondition.generateLeaseCondition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.microsoft.azure.storage.AccessCondition的用法示例。


在下文中一共展示了AccessCondition.generateLeaseCondition方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: openOutputStreamInternal

import com.microsoft.azure.storage.AccessCondition; //导入方法依赖的package包/类
/**
 * Opens an output stream object to write data to the file, using the specified lease ID, request options and
 * operation context. If the length is specified, a new file will be created with the length specified.
 * Otherwise, the file must already exist and a stream of its current length will be opened.
 * 
 * @param length
 *            A <code>long</code> which represents the length, in bytes, of the stream to create. This value must be
 *            null if the file already exists.
 * @param accessCondition
 *            An {@link AccessCondition} object which represents the access conditions for the file.
 * @param options
 *            A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudFileClient}).
 * @param opContext
 *            An {@link OperationContext} object which 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 FileOutputStream} object used to write data to the file.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 */
private FileOutputStream openOutputStreamInternal(Long length, AccessCondition accessCondition,
        FileRequestOptions options, OperationContext opContext) throws StorageException {
    if (opContext == null) {
        opContext = new OperationContext();
    }
    options = FileRequestOptions.applyDefaults(options, this.fileServiceClient);

    if (length != null) {
        if (options.getStoreFileContentMD5()) {
            throw new IllegalArgumentException(SR.FILE_MD5_NOT_POSSIBLE);
        }

        this.create(length, accessCondition, options, opContext);
    }
    else {
        this.downloadAttributes(accessCondition, options, opContext);
        length = this.getProperties().getLength();
    }

    if (accessCondition != null) {
        accessCondition = AccessCondition.generateLeaseCondition(accessCondition.getLeaseID());
    }

    return new FileOutputStream(this, length, accessCondition, options, opContext);
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:50,代码来源:CloudFile.java

示例2: testBlobLeaseAcquireAndRelease

import com.microsoft.azure.storage.AccessCondition; //导入方法依赖的package包/类
@Test
public void testBlobLeaseAcquireAndRelease() throws URISyntaxException, StorageException, IOException {
    final int length = 128;
    final CloudBlob blobRef = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, "test", 128, null);

    // Get Lease 
    OperationContext operationContext = new OperationContext();
    final String leaseID = blobRef.acquireLease(15, null /*proposed lease id */, null /*access condition*/,
            null/* BlobRequestOptions */, operationContext);
    final AccessCondition leaseCondition = AccessCondition.generateLeaseCondition(leaseID);
    assertTrue(operationContext.getLastResult().getStatusCode() == HttpURLConnection.HTTP_CREATED);

    tryUploadWithBadLease(length, blobRef, null, StorageErrorCodeStrings.LEASE_ID_MISSING);

    // Try to upload with lease
    blobRef.upload(BlobTestHelper.getRandomDataStream(length), -1, leaseCondition, null, null);

    // Release lease
    blobRef.releaseLease(leaseCondition);

    // now upload with no lease specified.
    blobRef.upload(BlobTestHelper.getRandomDataStream(length), -1);
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:24,代码来源:LeaseTests.java

示例3: getLeaseCondition

import com.microsoft.azure.storage.AccessCondition; //导入方法依赖的package包/类
/**
 * Return and access condition for this lease, or else null if
 * there's no lease.
 */
private AccessCondition getLeaseCondition(SelfRenewingLease lease) {
  AccessCondition leaseCondition = null;
  if (lease != null) {
    leaseCondition = AccessCondition.generateLeaseCondition(lease.getLeaseID());
  }
  return leaseCondition;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:12,代码来源:StorageInterfaceImpl.java

示例4: openOutputStreamInternal

import com.microsoft.azure.storage.AccessCondition; //导入方法依赖的package包/类
/**
 * Opens an output stream object to write data to the page blob, using the specified lease ID, request options and
 * operation context. If the length is specified, a new page blob will be created with the length specified.
 * Otherwise, the page blob must already exist and a stream of its current length will be opened.
 * 
 * @param length
 *            A <code>long</code> which represents the length, in bytes, of the stream to create. This value must be
 *            a multiple of 512 or null if the
 *            page blob already exists.
 * @param accessCondition
 *            An {@link AccessCondition} object which represents the access conditions for the blob.
 * @param options
 *            A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudBlobClient}).
 * @param opContext
 *            An {@link OperationContext} object which 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 BlobOutputStream} object used to write data to the blob.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 */
private BlobOutputStream openOutputStreamInternal(Long length, AccessCondition accessCondition,
        BlobRequestOptions options, OperationContext opContext) throws StorageException {
    if (opContext == null) {
        opContext = new OperationContext();
    }

    assertNoWriteOperationForSnapshot();

    options = BlobRequestOptions.applyDefaults(options, BlobType.PAGE_BLOB, this.blobServiceClient, false);

    if (options.getStoreBlobContentMD5()) {
        throw new IllegalArgumentException(SR.BLOB_MD5_NOT_SUPPORTED_FOR_PAGE_BLOBS);
    }

    if (length != null) {
        if (length % Constants.PAGE_SIZE != 0) {
            throw new IllegalArgumentException(SR.INVALID_PAGE_BLOB_LENGTH);
        }

        this.create(length, accessCondition, options, opContext);
    }
    else {
        this.downloadAttributes(accessCondition, options, opContext);
        length = this.getProperties().getLength();
    }

    if (accessCondition != null) {
        accessCondition = AccessCondition.generateLeaseCondition(accessCondition.getLeaseID());
    }

    return new BlobOutputStream(this, length, accessCondition, options, opContext);
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:58,代码来源:CloudPageBlob.java

示例5: testBlobLeaseBreak

import com.microsoft.azure.storage.AccessCondition; //导入方法依赖的package包/类
@Test
public void testBlobLeaseBreak() throws StorageException, IOException, URISyntaxException {
    final CloudBlob blobRef = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, "test", 128, null);

    // Get Lease
    String leaseID = blobRef.acquireLease();

    OperationContext operationContext = new OperationContext();
    final AccessCondition leaseCondition = AccessCondition.generateLeaseCondition(leaseID);
    blobRef.breakLease(0, leaseCondition, null/* BlobRequestOptions */, operationContext);
    assertTrue(operationContext.getLastResult().getStatusCode() == HttpURLConnection.HTTP_ACCEPTED);
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:13,代码来源:LeaseTests.java

示例6: testBlobLeaseRenew

import com.microsoft.azure.storage.AccessCondition; //导入方法依赖的package包/类
@Test
@Category(SlowTests.class)
public void testBlobLeaseRenew() throws StorageException, IOException, InterruptedException, URISyntaxException {
    final CloudBlob blobRef = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, "test", 128, null);

    // Get Lease
    final String leaseID = blobRef.acquireLease(15, null);
    Thread.sleep(1000);

    AccessCondition leaseCondition = AccessCondition.generateLeaseCondition(leaseID);
    OperationContext operationContext = new OperationContext();
    blobRef.renewLease(leaseCondition, null/* BlobRequestOptions */, operationContext);
    assertTrue(operationContext.getLastResult().getStatusCode() == HttpURLConnection.HTTP_OK);
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:15,代码来源:LeaseTests.java

示例7: openOutputStreamInternal

import com.microsoft.azure.storage.AccessCondition; //导入方法依赖的package包/类
/**
 * Opens an output stream object to write data to the page blob, using the specified lease ID, request options and
 * operation context. If the length is specified, a new page blob will be created with the length specified.
 * Otherwise, the page blob must already exist and a stream of its current length will be opened.
 * 
 * @param length
 *            A <code>long</code> which represents the length, in bytes, of the stream to create. This value must be
 *            a multiple of 512 or null if the
 *            page blob already exists.
 * @param premiumBlobTier
 *            A {@link PremiumPageBlobTier} object which represents the tier of the blob.
 * @param accessCondition
 *            An {@link AccessCondition} object which represents the access conditions for the blob.
 * @param options
 *            A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudBlobClient}).
 * @param opContext
 *            An {@link OperationContext} object which 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 BlobOutputStream} object used to write data to the blob.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 */
private BlobOutputStream openOutputStreamInternal(Long length, PremiumPageBlobTier premiumBlobTier, AccessCondition accessCondition,
        BlobRequestOptions options, OperationContext opContext) throws StorageException {
    if (opContext == null) {
        opContext = new OperationContext();
    }

    assertNoWriteOperationForSnapshot();

    options = BlobRequestOptions.populateAndApplyDefaults(options, BlobType.PAGE_BLOB, this.blobServiceClient, 
            false /* setStartTime */);

    if (options.getStoreBlobContentMD5()) {
        throw new IllegalArgumentException(SR.BLOB_MD5_NOT_SUPPORTED_FOR_PAGE_BLOBS);
    }

    if (length != null) {
        if (length % Constants.PAGE_SIZE != 0) {
            throw new IllegalArgumentException(SR.INVALID_PAGE_BLOB_LENGTH);
        }

        this.create(length, premiumBlobTier, accessCondition, options, opContext);
    }
    else {
        this.downloadAttributes(accessCondition, options, opContext);
        length = this.getProperties().getLength();
    }

    if (accessCondition != null) {
        accessCondition = AccessCondition.generateLeaseCondition(accessCondition.getLeaseID());
    }

    return new BlobOutputStream(this, length, accessCondition, options, opContext);
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:61,代码来源:CloudPageBlob.java

示例8: openOutputStreamInternal

import com.microsoft.azure.storage.AccessCondition; //导入方法依赖的package包/类
/**
 * Opens an output stream object to write data to the file, using the specified lease ID, request options and
 * operation context. If the length is specified, a new file will be created with the length specified.
 * Otherwise, the file must already exist and a stream of its current length will be opened.
 * 
 * @param length
 *            A <code>long</code> which represents the length, in bytes, of the stream to create. This value must be
 *            null if the file already exists.
 * @param accessCondition
 *            An {@link AccessCondition} object which represents the access conditions for the file.
 * @param options
 *            A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudFileClient}).
 * @param opContext
 *            An {@link OperationContext} object which 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 FileOutputStream} object used to write data to the file.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws URISyntaxException 
 */
private FileOutputStream openOutputStreamInternal(Long length, AccessCondition accessCondition,
        FileRequestOptions options, OperationContext opContext) throws StorageException, URISyntaxException {
    if (opContext == null) {
        opContext = new OperationContext();
    }

    this.getShare().assertNoSnapshot();

    options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient, false /* setStartTime */);

    if (length != null) {
        this.create(length, accessCondition, options, opContext);
    }
    else {
        if (options.getStoreFileContentMD5()) {
            throw new IllegalArgumentException(SR.FILE_MD5_NOT_POSSIBLE);
        }

        this.downloadAttributes(accessCondition, options, opContext);
        length = this.getProperties().getLength();
    }

    if (accessCondition != null) {
        accessCondition = AccessCondition.generateLeaseCondition(accessCondition.getLeaseID());
    }

    return new FileOutputStream(this, length, accessCondition, options, opContext);
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:54,代码来源:CloudFile.java

示例9: testBlobLeaseChange

import com.microsoft.azure.storage.AccessCondition; //导入方法依赖的package包/类
@Test
public void testBlobLeaseChange() throws StorageException, IOException, URISyntaxException {
    final int length = 128;
    final CloudBlob blobRef = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, "test", 128, null);

    // Get Lease 
    OperationContext operationContext = new OperationContext();
    final String leaseID1 = blobRef.acquireLease(15, null /*proposed lease id */, null /*access condition*/,
            null/* BlobRequestOptions */, operationContext);
    final AccessCondition leaseCondition1 = AccessCondition.generateLeaseCondition(leaseID1);
    assertTrue(operationContext.getLastResult().getStatusCode() == HttpURLConnection.HTTP_CREATED);

    final String leaseID2 = UUID.randomUUID().toString();
    final AccessCondition leaseCondition2 = AccessCondition.generateLeaseCondition(leaseID2);

    // Try to upload without lease
    tryUploadWithBadLease(length, blobRef, null, StorageErrorCodeStrings.LEASE_ID_MISSING);

    // Try to upload with incorrect lease
    tryUploadWithBadLease(length, blobRef, leaseCondition2,
            StorageErrorCodeStrings.LEASE_ID_MISMATCH_WITH_BLOB_OPERATION);

    // Try to upload with correct lease
    blobRef.upload(BlobTestHelper.getRandomDataStream(length), -1, leaseCondition1, null, null);

    // Fail to change the lease with a bad accessCondition
    try {
        blobRef.changeLease(leaseID2, leaseCondition2);
        fail("Did not throw expected exception.");
    }
    catch (final StorageException ex) {
        assertEquals(ex.getHttpStatusCode(), 409);
        assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.LEASE_ID_MISMATCH_WITH_LEASE_OPERATION);
    }

    // Change the lease
    blobRef.changeLease(leaseID2, leaseCondition1);

    // Try to upload without lease
    tryUploadWithBadLease(length, blobRef, null, StorageErrorCodeStrings.LEASE_ID_MISSING);

    // Try to upload with incorrect lease
    tryUploadWithBadLease(length, blobRef, leaseCondition1,
            StorageErrorCodeStrings.LEASE_ID_MISMATCH_WITH_BLOB_OPERATION);

    // Try to upload with correct lease
    blobRef.upload(BlobTestHelper.getRandomDataStream(length), -1, leaseCondition2, null, null);
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:49,代码来源:LeaseTests.java


注:本文中的com.microsoft.azure.storage.AccessCondition.generateLeaseCondition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。