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

Commit 30588c6

Browse files
committed
CR feedback
1 parent 2ab7205 commit 30588c6

File tree

5 files changed

+147
-29
lines changed

5 files changed

+147
-29
lines changed

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,6 @@ public void testCopyBlockBlobWithSyncMd5() throws URISyntaxException, StorageExc
625625
CloudBlockBlob destination = this.container.getBlockBlobReference("destination");
626626
destination.commitBlockList(new ArrayList<BlockEntry>());
627627

628-
String copyId = null;
629628
boolean exceptionThrown = false;
630629
// Test that setting an md5 without sync copy is disallowed.
631630
try {
@@ -650,7 +649,7 @@ public void testCopyBlockBlobWithSyncMd5() throws URISyntaxException, StorageExc
650649
String md5 = Base64.encode(MessageDigest.getInstance("MD5").digest(data.getBytes()));
651650

652651
// Start a sync copy with a correct md5. Should succeed.
653-
copyId = destination.startCopy(source, md5,true, null, null, null, null);
652+
destination.startCopy(source, md5,true, null, null, null, null);
654653
}
655654
assertTrue(exceptionThrown);
656655

@@ -713,7 +712,7 @@ public void eventOccurred(SendingRequestEvent eventArg) {
713712
}
714713
});
715714

716-
copyDestination.startCopy(copySource.getUri(), null, false, null, null, null, ctx);
715+
copyDestination.startCopy(copySource.getUri(), null, false, null, null, null, null, ctx);
717716
copyDestination.startCopy(copySource, null, false, null, null, null, ctx);
718717
}
719718

@@ -1258,19 +1257,19 @@ public void testUploadBlockFromURI() throws URISyntaxException, StorageException
12581257
.generateRandomBlobNameWithPrefix("copyBlob"));
12591258
Map<String, BlockEntry> blocks = BlobTestHelper.getBlockEntryList(2);
12601259
// Copy the first half of the blob.
1261-
blob2.uploadBlockFromURI(((BlockEntry)blocks.values().toArray()[0]).getId(), blob.getUri(), 0, 5L);
1260+
blob2.createBlockFromURI(((BlockEntry)blocks.values().toArray()[0]).getId(), blob.getUri(), 0L, 5L);
12621261

12631262
// Copy the second half of the blob, specifying the MD5 and setting null for the length to indicate the remainder of the blob.
12641263
String md5 = Base64.encode(MessageDigest.getInstance("MD5").digest(text.substring(5).getBytes()));
12651264
boolean exceptionThrown = false;
12661265
try {
1267-
blob2.uploadBlockFromURI(((BlockEntry) blocks.values().toArray()[1]).getId(), blob.getUri(), 5, null,
1266+
blob2.createBlockFromURI(((BlockEntry) blocks.values().toArray()[1]).getId(), blob.getUri(), 5L, null,
12681267
Base64.encode(MessageDigest.getInstance("MD5").digest("garbage".getBytes())), null, null, null);
12691268
}
12701269
catch (StorageException e) {
12711270
exceptionThrown = true;
12721271
assertEquals("Md5Mismatch", e.getErrorCode());
1273-
blob2.uploadBlockFromURI(((BlockEntry) blocks.values().toArray()[1]).getId(), blob.getUri(), 5, null, md5, null, null, null);
1272+
blob2.createBlockFromURI(((BlockEntry) blocks.values().toArray()[1]).getId(), blob.getUri(), 5L, null, md5, null, null, null);
12741273
}
12751274
assertTrue(exceptionThrown);
12761275

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

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,47 @@ public static HttpURLConnection appendBlock(final URI uri, final BlobRequestOpti
200200
return request;
201201
}
202202

203+
/**
204+
* Creates a request to copy a blob, Sign with 0 length.
205+
*
206+
* @param uri
207+
* A <code>java.net.URI</code> object that specifies the absolute URI.
208+
* @param blobOptions
209+
* A {@link BlobRequestOptions} object that specifies execution options such as retry policy and timeout
210+
* settings for the operation. Specify <code>null</code> to use the request options specified on the
211+
* {@link CloudBlobClient}.
212+
* @param opContext
213+
* An {@link OperationContext} object that represents the context for the current operation. This object
214+
* is used to track requests to the storage service, and to provide additional runtime information about
215+
* the operation.
216+
* @param sourceAccessCondition
217+
* An {@link AccessCondition} object that represents the access conditions for the source blob.
218+
* @param destinationAccessCondition
219+
* An {@link AccessCondition} object that represents the access conditions for the destination blob.
220+
* @param source
221+
* The canonical path to the source blob, in the form /<account-name>/<container-name>/<blob-name>.
222+
* @param sourceSnapshotID
223+
* The snapshot version, if the source blob is a snapshot.
224+
* @param incrementalCopy
225+
* A boolean indicating whether or not this is an incremental copy.
226+
* @param premiumPageBlobTier
227+
* A {@link PremiumPageBlobTier} object which represents the tier of the blob.
228+
* @return a HttpURLConnection configured for the operation.
229+
* @throws StorageException
230+
* an exception representing any error which occurred during the operation.
231+
* @throws IllegalArgumentException
232+
* @throws IOException
233+
* @throws URISyntaxException
234+
*/
235+
public static HttpURLConnection copyFrom(final URI uri, final BlobRequestOptions blobOptions,
236+
final OperationContext opContext, final AccessCondition sourceAccessCondition,
237+
final AccessCondition destinationAccessCondition, String source, final String sourceSnapshotID,
238+
final boolean incrementalCopy, final PremiumPageBlobTier premiumPageBlobTier)
239+
throws StorageException, IOException, URISyntaxException {
240+
241+
return copyFrom(uri, blobOptions, opContext, sourceAccessCondition, destinationAccessCondition, source, sourceSnapshotID, incrementalCopy, false, null, premiumPageBlobTier);
242+
}
243+
203244
/**
204245
* Creates a request to copy a blob, Sign with 0 length.
205246
*
@@ -221,7 +262,7 @@ public static HttpURLConnection appendBlock(final URI uri, final BlobRequestOpti
221262
* The canonical path to the source blob, in the form /<account-name>/<container-name>/<blob-name>.
222263
* @param contentMd5
223264
* An optional hash value used to ensure transactional integrity for the operation. May be {@code null}
224-
* or an empty string.
265+
* or an empty string. If the blob being copied is within the same account, this value will be ignored.
225266
* @param sourceSnapshotID
226267
* The snapshot version, if the source blob is a snapshot.
227268
* @param incrementalCopy
@@ -603,6 +644,10 @@ private static void addSourceRange(HttpURLConnection request, Long offset, Long
603644
* Number of bytes in the range.
604645
*/
605646
private static void addRangeImpl(String header, HttpURLConnection request, Long offset, Long count) {
647+
if (count != null) {
648+
Utility.assertNotNull("offset", offset);
649+
Utility.assertInBounds("count", count, 1, Long.MAX_VALUE);
650+
}
606651
if (offset != null) {
607652
long rangeStart = offset;
608653
long rangeEnd;
@@ -1311,7 +1356,7 @@ else if (blobType == BlobType.APPEND_BLOB){
13111356
}
13121357

13131358
/**
1314-
* Constructs a HttpURLConnection to upload a block. Sign with length of block data.
1359+
* Constructs a HttpURLConnection to create a block. Sign with length of block data.
13151360
*
13161361
* @param uri
13171362
* A <code>java.net.URI</code> object that specifies the absolute URI.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public final String startCopy(final CloudAppendBlob sourceBlob, final AccessCond
224224
source = sourceBlob.getServiceClient().getCredentials().transformUri(sourceBlob.getSnapshotQualifiedUri());
225225
}
226226

227-
return this.startCopy(source, null, false, sourceAccessCondition, destinationAccessCondition, options, opContext);
227+
return this.startCopy(source, null /* contentMd5 */ , false /* syncCopy */, null /* premiumPageBlobTier */, sourceAccessCondition, destinationAccessCondition, options, opContext);
228228
}
229229

230230
/**

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

Lines changed: 41 additions & 8 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, null /* contentMd5 */, false /* syncCopy */, null /* sourceAccessCondition */, null /* destinationAccessCondition */,
632+
return this.startCopy(source, null /* sourceAccessCondition */, null /* destinationAccessCondition */,
633633
null /* options */, null /* opContext */);
634634
}
635635

@@ -640,11 +640,6 @@ 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.
648643
* @param sourceAccessCondition
649644
* An {@link AccessCondition} object that represents the access conditions for the source.
650645
* @param destinationAccessCondition
@@ -665,10 +660,48 @@ public final String startCopy(final URI source) throws StorageException {
665660
*
666661
*/
667662
@DoesServiceRequest
668-
public final String startCopy(final URI source, String contentMd5, boolean syncCopy, final AccessCondition sourceAccessCondition,
663+
public final String startCopy(final URI source, final AccessCondition sourceAccessCondition,
669664
final AccessCondition destinationAccessCondition, BlobRequestOptions options, OperationContext opContext)
670665
throws StorageException {
671-
return this.startCopy(source, contentMd5, syncCopy, null /* premiumPageBlobTier */, sourceAccessCondition, destinationAccessCondition, options, opContext);
666+
return this.startCopy(source,null /* premiumPageBlobTier */, sourceAccessCondition, destinationAccessCondition, options, opContext);
667+
}
668+
669+
/**
670+
* Requests the service to start copying a URI's contents, properties, and metadata to a new blob, using the
671+
* specified premium page blob tier, access conditions, lease ID, request options, and operation context.
672+
* <p>
673+
* Note: Setting the premiumPageBlobTier is only supported for premium accounts.
674+
* </p>
675+
* @param source
676+
* A <code>java.net.URI</code> The source URI. URIs for resources outside of Azure
677+
* may only be copied into block blobs.
678+
* @param premiumPageBlobTier
679+
* A {@link PremiumPageBlobTier} object which represents the tier of the blob.
680+
* @param sourceAccessCondition
681+
* An {@link AccessCondition} object that represents the access conditions for the source.
682+
* @param destinationAccessCondition
683+
* An {@link AccessCondition} object that represents the access conditions for the destination.
684+
* @param options
685+
* A {@link BlobRequestOptions} object that specifies any additional options for the request.
686+
* Specifying <code>null</code> will use the default request options from the associated
687+
* service client ({@link CloudBlobClient}).
688+
* @param opContext
689+
* An {@link OperationContext} object that represents the context for the current operation.
690+
* This object is used to track requests to the storage service, and to provide additional
691+
* runtime information about the operation.
692+
*
693+
* @return A <code>String</code> which represents the copy ID associated with the copy operation.
694+
*
695+
* @throws StorageException
696+
* If a storage service error occurred.
697+
*
698+
*/
699+
@DoesServiceRequest
700+
protected final String startCopy(final URI source, final PremiumPageBlobTier premiumPageBlobTier, final AccessCondition sourceAccessCondition,
701+
final AccessCondition destinationAccessCondition, BlobRequestOptions options, OperationContext opContext)
702+
throws StorageException {
703+
return startCopy(source, null /* contentMd5 */, false /* syncCopy */, premiumPageBlobTier, sourceAccessCondition,
704+
destinationAccessCondition, options, opContext);
672705
}
673706

674707
/**

0 commit comments

Comments
 (0)