本文整理汇总了Java中com.microsoft.azure.storage.AccessCondition.generateIfMatchCondition方法的典型用法代码示例。如果您正苦于以下问题:Java AccessCondition.generateIfMatchCondition方法的具体用法?Java AccessCondition.generateIfMatchCondition怎么用?Java AccessCondition.generateIfMatchCondition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.microsoft.azure.storage.AccessCondition
的用法示例。
在下文中一共展示了AccessCondition.generateIfMatchCondition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBlobMultiConditionHeaders
import com.microsoft.azure.storage.AccessCondition; //导入方法依赖的package包/类
@Test
@Category({ DevFabricTests.class, DevStoreTests.class })
public void testBlobMultiConditionHeaders() throws URISyntaxException, StorageException, IOException {
final String blockBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob");
final CloudBlockBlob blockBlobRef = this.container.getBlockBlobReference(blockBlobName);
final int length = 2 * 1024;
ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length);
OperationContext context = new OperationContext();
blockBlobRef.upload(srcStream, -1, null, null, context);
AccessCondition condition = AccessCondition.generateIfMatchCondition(context.getLastResult().getEtag());
condition.setIfUnmodifiedSinceDate(context.getLastResult().getStartDate());
StorageEvent<SendingRequestEvent> event = new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject();
assertNotNull(connection.getRequestProperty("If-Unmodified-Since"));
assertNotNull(connection.getRequestProperty("If-Match"));
}
};
context.getSendingRequestEventHandler().addListener(event);
blockBlobRef.upload(srcStream, -1, condition, null, context);
}
示例2: BlobInputStream
import com.microsoft.azure.storage.AccessCondition; //导入方法依赖的package包/类
/**
* Initializes a new instance of the BlobInputStream class.
*
* @param parentBlob
* A {@link CloudBlob} object which represents the blob that this stream is associated with.
* @param accessCondition
* An {@link AccessCondition} object which represents the access conditions for the blob.
* @param options
* A {@link BlobRequestOptions} object which represents that specifies any additional options for the
* request.
* @param opContext
* An {@link OperationContext} object which is used to track the execution of the operation.
*
* @throws StorageException
* An exception representing any error which occurred during the operation.
*/
@DoesServiceRequest
protected BlobInputStream(final CloudBlob parentBlob, final AccessCondition accessCondition,
final BlobRequestOptions options, final OperationContext opContext) throws StorageException {
this.parentBlobRef = parentBlob;
this.parentBlobRef.assertCorrectBlobType();
this.options = new BlobRequestOptions(options);
this.opContext = opContext;
this.streamFaulted = false;
this.currentAbsoluteReadPosition = 0;
this.readSize = parentBlob.getStreamMinimumReadSizeInBytes();
if (options.getUseTransactionalContentMD5() && this.readSize > 4 * Constants.MB) {
throw new IllegalArgumentException(SR.INVALID_RANGE_CONTENT_MD5_HEADER);
}
parentBlob.downloadAttributes(accessCondition, this.options, this.opContext);
this.retrievedContentMD5Value = parentBlob.getProperties().getContentMD5();
// Will validate it if it was returned
this.validateBlobMd5 = !options.getDisableContentMD5Validation()
&& !Utility.isNullOrEmpty(this.retrievedContentMD5Value);
// Validates the first option, and sets future requests to use if match
// request option.
// If there is an existing conditional validate it, as we intend to
// replace if for future requests.
String previousLeaseId = null;
if (accessCondition != null) {
previousLeaseId = accessCondition.getLeaseID();
if (!accessCondition.verifyConditional(this.parentBlobRef.getProperties().getEtag(), this.parentBlobRef
.getProperties().getLastModified())) {
throw new StorageException(StorageErrorCode.CONDITION_FAILED.toString(),
SR.INVALID_CONDITIONAL_HEADERS, HttpURLConnection.HTTP_PRECON_FAILED, null, null);
}
}
this.accessCondition = AccessCondition.generateIfMatchCondition(this.parentBlobRef.getProperties().getEtag());
this.accessCondition.setLeaseID(previousLeaseId);
this.streamLength = parentBlob.getProperties().getLength();
if (this.validateBlobMd5) {
try {
this.md5Digest = MessageDigest.getInstance("MD5");
}
catch (final NoSuchAlgorithmException e) {
// This wont happen, throw fatal.
throw Utility.generateNewUnexpectedStorageException(e);
}
}
this.reposition(0);
}
示例3: FileInputStream
import com.microsoft.azure.storage.AccessCondition; //导入方法依赖的package包/类
/**
* Initializes a new instance of the FileInputStream class.
*
* @param parentFile
* A {@link CloudFile} object which represents the file that this stream is associated with.
* @param accessCondition
* An {@link AccessCondition} object which represents the access conditions for the file.
* @param options
* A {@link FileRequestOptions} object which represents that specifies any additional options for the
* request.
* @param opContext
* An {@link OperationContext} object which is used to track the execution of the operation.
*
* @throws StorageException
* An exception representing any error which occurred during the operation.
*/
@DoesServiceRequest
protected FileInputStream(final CloudFile parentFile, final AccessCondition accessCondition,
final FileRequestOptions options, final OperationContext opContext) throws StorageException {
this.parentFileRef = parentFile;
this.options = new FileRequestOptions(options);
this.opContext = opContext;
this.streamFaulted = false;
this.currentAbsoluteReadPosition = 0;
this.readSize = parentFile.getStreamMinimumReadSizeInBytes();
if (options.getUseTransactionalContentMD5() && this.readSize > 4 * Constants.MB) {
throw new IllegalArgumentException(SR.INVALID_RANGE_CONTENT_MD5_HEADER);
}
parentFile.downloadAttributes(accessCondition, this.options, this.opContext);
this.retrievedContentMD5Value = parentFile.getProperties().getContentMD5();
// Will validate it if it was returned
this.validateFileMd5 = !options.getDisableContentMD5Validation()
&& !Utility.isNullOrEmpty(this.retrievedContentMD5Value);
String previousLeaseId = null;
if (accessCondition != null) {
previousLeaseId = accessCondition.getLeaseID();
}
this.accessCondition = AccessCondition.generateIfMatchCondition(this.parentFileRef.getProperties().getEtag());
this.accessCondition.setLeaseID(previousLeaseId);
this.streamLength = parentFile.getProperties().getLength();
if (this.validateFileMd5) {
try {
this.md5Digest = MessageDigest.getInstance("MD5");
}
catch (final NoSuchAlgorithmException e) {
// This wont happen, throw fatal.
throw Utility.generateNewUnexpectedStorageException(e);
}
}
this.reposition(0);
}