Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 9548d0f

Browse files
committed
Added Md5 support
1 parent f4150e6 commit 9548d0f

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobRequest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,13 @@ public static HttpURLConnection appendBlock(final URI uri, final BlobRequestOpti
235235
public static HttpURLConnection copyFrom(final URI uri, final BlobRequestOptions blobOptions,
236236
final OperationContext opContext, final AccessCondition sourceAccessCondition,
237237
final AccessCondition destinationAccessCondition, String source, final String sourceSnapshotID,
238-
final boolean incrementalCopy, final boolean syncCopy, final PremiumPageBlobTier premiumPageBlobTier)
238+
final boolean incrementalCopy, final boolean syncCopy, final String contentMd5, final PremiumPageBlobTier premiumPageBlobTier)
239239
throws StorageException, IOException, URISyntaxException {
240240

241+
if (!syncCopy && !Utility.isNullOrEmpty(contentMd5)) {
242+
throw new IllegalArgumentException(SR.INVALID_COPY_MD5_OPERATION);
243+
}
244+
241245
if (sourceSnapshotID != null) {
242246
source = source.concat("?snapshot=");
243247
source = source.concat(sourceSnapshotID);
@@ -274,6 +278,10 @@ public static HttpURLConnection copyFrom(final URI uri, final BlobRequestOptions
274278
request.setRequestProperty(HeaderConstants.REQUIRES_SYNC_HEADER, Constants.TRUE);
275279
}
276280

281+
if (!Utility.isNullOrEmpty(contentMd5)) {
282+
request.setRequestProperty(HeaderConstants.SOURCE_CONTENT_MD5_HEADER, contentMd5);
283+
}
284+
277285
return request;
278286
}
279287

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ public String preProcessResponse(CloudBlob blob, CloudBlobClient client, Operati
629629
*/
630630
@DoesServiceRequest
631631
public final String startCopy(final URI source) throws StorageException {
632-
return this.startCopy(source, false /* sync copy */, null /* sourceAccessCondition */, null /* destinationAccessCondition */,
632+
return this.startCopy(source, null /* contentMd5 */, false /* syncCopy */, null /* sourceAccessCondition */, null /* destinationAccessCondition */,
633633
null /* options */, null /* opContext */);
634634
}
635635

@@ -640,6 +640,11 @@ public final String startCopy(final URI source) throws StorageException {
640640
* @param source
641641
* A <code>java.net.URI</code> The source URI. URIs for resources outside of Azure
642642
* may only be copied into block blobs.
643+
* @param contentMd5
644+
* An optional hash value used to ensure transactional integrity for the operation. May be
645+
* <code>null</code> or empty.
646+
* @param syncCopy
647+
* A <code>boolean</code> which indicates if the copy should be done synchronously on the service.
643648
* @param sourceAccessCondition
644649
* An {@link AccessCondition} object that represents the access conditions for the source.
645650
* @param destinationAccessCondition
@@ -660,10 +665,10 @@ public final String startCopy(final URI source) throws StorageException {
660665
*
661666
*/
662667
@DoesServiceRequest
663-
public final String startCopy(final URI source, boolean syncCopy, final AccessCondition sourceAccessCondition,
668+
public final String startCopy(final URI source, String contentMd5, boolean syncCopy, final AccessCondition sourceAccessCondition,
664669
final AccessCondition destinationAccessCondition, BlobRequestOptions options, OperationContext opContext)
665670
throws StorageException {
666-
return this.startCopy(source, syncCopy, null /* premiumPageBlobTier */, sourceAccessCondition, destinationAccessCondition, options, opContext);
671+
return this.startCopy(source, contentMd5, syncCopy, null /* premiumPageBlobTier */, sourceAccessCondition, destinationAccessCondition, options, opContext);
667672
}
668673

669674
/**
@@ -675,6 +680,9 @@ public final String startCopy(final URI source, boolean syncCopy, final AccessCo
675680
* @param source
676681
* A <code>java.net.URI</code> The source URI. URIs for resources outside of Azure
677682
* may only be copied into block blobs.
683+
* @param contentMd5
684+
* An optional hash value used to ensure transactional integrity for the operation. May be
685+
* <code>null</code> or empty.
678686
* @param syncCopy
679687
* A <code>boolean</code> which indicates if the copy should be done synchronously on the service.
680688
* @param premiumPageBlobTier
@@ -699,7 +707,7 @@ public final String startCopy(final URI source, boolean syncCopy, final AccessCo
699707
*
700708
*/
701709
@DoesServiceRequest
702-
protected final String startCopy(final URI source, boolean syncCopy, final PremiumPageBlobTier premiumPageBlobTier, final AccessCondition sourceAccessCondition,
710+
protected final String startCopy(final URI source, String contentMd5, boolean syncCopy, final PremiumPageBlobTier premiumPageBlobTier, final AccessCondition sourceAccessCondition,
703711
final AccessCondition destinationAccessCondition, BlobRequestOptions options, OperationContext opContext)
704712
throws StorageException {
705713
if (opContext == null) {
@@ -710,12 +718,12 @@ protected final String startCopy(final URI source, boolean syncCopy, final Premi
710718
options = BlobRequestOptions.populateAndApplyDefaults(options, this.properties.getBlobType(), this.blobServiceClient);
711719

712720
return ExecutionEngine.executeWithRetry(this.blobServiceClient, this,
713-
this.startCopyImpl(source, syncCopy, false /* incrementalCopy */, premiumPageBlobTier, sourceAccessCondition, destinationAccessCondition, options),
721+
this.startCopyImpl(source, contentMd5, syncCopy, false /* incrementalCopy */, premiumPageBlobTier, sourceAccessCondition, destinationAccessCondition, options),
714722
options.getRetryPolicyFactory(), opContext);
715723
}
716724

717725
protected StorageRequest<CloudBlobClient, CloudBlob, String> startCopyImpl(
718-
final URI source, final boolean syncCopy, final boolean incrementalCopy, final PremiumPageBlobTier premiumPageBlobTier, final AccessCondition sourceAccessCondition,
726+
final URI source, final String contentMd5, final boolean syncCopy, final boolean incrementalCopy, final PremiumPageBlobTier premiumPageBlobTier, final AccessCondition sourceAccessCondition,
719727
final AccessCondition destinationAccessCondition, final BlobRequestOptions options) {
720728

721729
final StorageRequest<CloudBlobClient, CloudBlob, String> putRequest =
@@ -727,7 +735,7 @@ public HttpURLConnection buildRequest(CloudBlobClient client, CloudBlob blob, Op
727735
// toASCIIString() must be used in order to appropriately encode the URI
728736
return BlobRequest.copyFrom(blob.getTransformedAddress(context).getUri(this.getCurrentLocation()),
729737
options, context, sourceAccessCondition, destinationAccessCondition, source.toASCIIString(),
730-
blob.snapshotID, incrementalCopy, syncCopy, premiumPageBlobTier);
738+
blob.snapshotID, incrementalCopy, syncCopy, contentMd5, premiumPageBlobTier);
731739
}
732740

733741
@Override

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlockBlob.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected CloudBlockBlob(String blobName, String snapshotID, CloudBlobContainer
177177
*/
178178
@DoesServiceRequest
179179
public final String startCopy(final CloudBlockBlob sourceBlob) throws StorageException, URISyntaxException {
180-
return this.startCopy(sourceBlob, false /* syncCopy */, null /* sourceAccessCondition */,
180+
return this.startCopy(sourceBlob, null /* contentMd5 */, false /* syncCopy */, null /* sourceAccessCondition */,
181181
null /* destinationAccessCondition */, null /* options */, null /* opContext */);
182182
}
183183

@@ -187,6 +187,11 @@ public final String startCopy(final CloudBlockBlob sourceBlob) throws StorageExc
187187
*
188188
* @param sourceBlob
189189
* A <code>CloudBlockBlob</code> object that represents the source blob to copy.
190+
* @param contentMd5
191+
* An optional hash value used to ensure transactional integrity for the operation. May be
192+
* <code>null</code> or empty.
193+
* @param syncCopy
194+
* A <code>boolean</code> to enable synchronous server copy of blobs.
190195
* @param sourceAccessCondition
191196
* An {@link AccessCondition} object that represents the access conditions for the source blob.
192197
* @param destinationAccessCondition
@@ -208,7 +213,7 @@ public final String startCopy(final CloudBlockBlob sourceBlob) throws StorageExc
208213
*
209214
*/
210215
@DoesServiceRequest
211-
public final String startCopy(final CloudBlockBlob sourceBlob, boolean syncCopy, final AccessCondition sourceAccessCondition,
216+
public final String startCopy(final CloudBlockBlob sourceBlob, String contentMd5, boolean syncCopy, final AccessCondition sourceAccessCondition,
212217
final AccessCondition destinationAccessCondition, BlobRequestOptions options, OperationContext opContext)
213218
throws StorageException, URISyntaxException {
214219
Utility.assertNotNull("sourceBlob", sourceBlob);
@@ -219,7 +224,7 @@ public final String startCopy(final CloudBlockBlob sourceBlob, boolean syncCopy,
219224
source = sourceBlob.getServiceClient().getCredentials().transformUri(sourceBlob.getSnapshotQualifiedUri());
220225
}
221226

222-
return this.startCopy(source, syncCopy, sourceAccessCondition, destinationAccessCondition, options, opContext);
227+
return this.startCopy(source, contentMd5, syncCopy, sourceAccessCondition, destinationAccessCondition, options, opContext);
223228
}
224229

225230
/**
@@ -236,7 +241,7 @@ public final String startCopy(final CloudBlockBlob sourceBlob, boolean syncCopy,
236241
*/
237242
@DoesServiceRequest
238243
public final String startCopy(final CloudFile sourceFile) throws StorageException, URISyntaxException {
239-
return this.startCopy(sourceFile, false /* syncCopy */, null /* sourceAccessCondition */,
244+
return this.startCopy(sourceFile, null /* sourceAccessCondition */,
240245
null /* destinationAccessCondition */, null /* options */, null /* opContext */);
241246
}
242247

@@ -267,12 +272,12 @@ public final String startCopy(final CloudFile sourceFile) throws StorageExceptio
267272
* If the resource URI is invalid.
268273
*/
269274
@DoesServiceRequest
270-
public final String startCopy(final CloudFile sourceFile, boolean syncCopy, final AccessCondition sourceAccessCondition,
275+
public final String startCopy(final CloudFile sourceFile, final AccessCondition sourceAccessCondition,
271276
final AccessCondition destinationAccessCondition, BlobRequestOptions options, OperationContext opContext)
272277
throws StorageException, URISyntaxException {
273278
Utility.assertNotNull("sourceFile", sourceFile);
274279
return this.startCopy(
275-
sourceFile.getServiceClient().getCredentials().transformUri(sourceFile.getUri()), syncCopy,
280+
sourceFile.getServiceClient().getCredentials().transformUri(sourceFile.getUri()), null, false,
276281
sourceAccessCondition, destinationAccessCondition, options, opContext);
277282
}
278283

microsoft-azure-storage/src/com/microsoft/azure/storage/core/SR.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public class SR {
9090
public static final String INVALID_CONNECTION_STRING_DEV_STORE_NOT_TRUE = "Invalid connection string, the UseDevelopmentStorage key must always be paired with 'true'. Remove the flag entirely otherwise.";
9191
public static final String INVALID_CONTENT_LENGTH = "ContentLength must be set to -1 or positive Long value.";
9292
public static final String INVALID_CONTENT_TYPE = "An incorrect Content-Type was returned from the server.";
93+
public static final String INVALID_COPY_MD5_OPERATION = "MD5 can only be specified with a synchronous copy operation.";
9394
public static final String INVALID_CORS_RULE = "A CORS rule must contain at least one allowed origin and allowed method, and MaxAgeInSeconds cannot have a value less than zero.";
9495
public static final String INVALID_DATE_STRING = "Invalid Date String: %s.";
9596
public static final String INVALID_EDMTYPE_VALUE = "Invalid value '%s' for EdmType.";

0 commit comments

Comments
 (0)