Skip to content

Commit 11a2da2

Browse files
code refactoring based on latest review comments
1 parent 2b2e86d commit 11a2da2

5 files changed

Lines changed: 16 additions & 116 deletions

File tree

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/util/BuilderHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public static HttpPipeline buildPipeline(StorageSharedKeyCredential storageShare
9797
// Closest to API goes first, closest to wire goes last.
9898
List<HttpPipelinePolicy> policies = new ArrayList<>();
9999

100+
policies.add(new StorageContentValidationDecoderPolicy());
101+
100102
policies.add(getUserAgentPolicy(configuration, logOptions, clientOptions));
101103
policies.add(new RequestIdPolicy());
102104

@@ -116,8 +118,6 @@ public static HttpPipeline buildPipeline(StorageSharedKeyCredential storageShare
116118
}
117119
policies.add(new MetadataValidationPolicy());
118120

119-
policies.add(new StorageContentValidationDecoderPolicy());
120-
121121
if (storageSharedKeyCredential != null) {
122122
policies.add(new StorageSharedKeyCredentialPolicy(storageSharedKeyCredential));
123123
}

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/specialized/BlobAsyncClientBase.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ public Mono<Response<BlobProperties>> downloadToFileWithResponse(String filePath
15751575
BlobRequestConditions requestConditions, boolean rangeGetContentMd5, Set<OpenOption> openOptions) {
15761576
try {
15771577
final com.azure.storage.common.ParallelTransferOptions finalParallelTransferOptions
1578-
= parallelTransferOptions == null ? null : ModelHelper.wrapBlobOptions(parallelTransferOptions);
1578+
= ModelHelper.wrapBlobOptions(ModelHelper.populateAndApplyDefaults(parallelTransferOptions));
15791579
return withContext(
15801580
context -> downloadToFileWithResponse(new BlobDownloadToFileOptions(filePath).setRange(range)
15811581
.setParallelTransferOptions(finalParallelTransferOptions)
@@ -1629,7 +1629,7 @@ Mono<Response<BlobProperties>> downloadToFileWithResponse(BlobDownloadToFileOpti
16291629
StorageImplUtils.assertNotNull("options", options);
16301630

16311631
BlobRange finalRange = options.getRange() == null ? new BlobRange(0) : options.getRange();
1632-
com.azure.storage.common.ParallelTransferOptions finalParallelTransferOptions
1632+
final com.azure.storage.common.ParallelTransferOptions finalParallelTransferOptions
16331633
= ModelHelper.populateAndApplyDefaults(options.getParallelTransferOptions());
16341634
BlobRequestConditions finalConditions
16351635
= options.getRequestConditions() == null ? new BlobRequestConditions() : options.getRequestConditions();
@@ -1681,6 +1681,7 @@ private Mono<Response<BlobProperties>> downloadToFileImpl(AsynchronousFileChanne
16811681
int numChunks = ChunkedDownloadUtils.calculateNumBlocks(newCount,
16821682
finalParallelTransferOptions.getBlockSizeLong());
16831683

1684+
// In case it is an empty blob, this ensures we still actually perform a download operation.
16841685
numChunks = numChunks == 0 ? 1 : numChunks;
16851686

16861687
BlobDownloadAsyncResponse initialResponse = setupTuple3.getT3();
@@ -1692,6 +1693,7 @@ private Mono<Response<BlobProperties>> downloadToFileImpl(AsynchronousFileChanne
16921693
progressReporter == null ? null : progressReporter.createChild()).flux()),
16931694
finalParallelTransferOptions.getMaxConcurrency())
16941695

1696+
// Only the first download call returns a value.
16951697
.then(Mono.just(ModelHelper.buildBlobPropertiesResponse(initialResponse)));
16961698
});
16971699
}

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/specialized/BlobClientBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ public Response<BlobProperties> downloadToFileWithResponse(String filePath, Blob
15671567
BlobRequestConditions requestConditions, boolean rangeGetContentMd5, Set<OpenOption> openOptions,
15681568
Duration timeout, Context context) {
15691569
final com.azure.storage.common.ParallelTransferOptions finalParallelTransferOptions
1570-
= parallelTransferOptions == null ? null : ModelHelper.wrapBlobOptions(parallelTransferOptions);
1570+
= ModelHelper.wrapBlobOptions(ModelHelper.populateAndApplyDefaults(parallelTransferOptions));
15711571
return downloadToFileWithResponse(new BlobDownloadToFileOptions(filePath).setRange(range)
15721572
.setParallelTransferOptions(finalParallelTransferOptions)
15731573
.setDownloadRetryOptions(downloadRetryOptions)

sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/contentvalidation/StorageCrc64Calculator.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,6 +2400,8 @@ public class StorageCrc64Calculator {
24002400

24012401
/**
24022402
* Computes the CRC64 checksum for the given byte array using the Azure Storage CRC64 polynomial.
2403+
* This method processes the input data in chunks of 32 bytes for efficiency and uses lookup tables
2404+
* to update the CRC values.
24032405
*
24042406
* @param src the byte array for which the CRC64 checksum is to be computed.
24052407
* @param uCrc the initial CRC value.
@@ -2420,7 +2422,7 @@ public static long compute(byte[] src, long uCrc) {
24202422
* @return the computed CRC64 checksum.
24212423
*/
24222424
public static long compute(byte[] src, int offset, int length, long uCrc) {
2423-
int pData = 0;
2425+
int pData = offset;
24242426
long uSize = length;
24252427
long uBytes, uStop;
24262428

@@ -2437,7 +2439,7 @@ public static long compute(byte[] src, int offset, int length, long uCrc) {
24372439
uSize -= uStop;
24382440
uCrc0 = uCrc;
24392441

2440-
ByteBuffer buffer = ByteBuffer.wrap(src, offset, length).order(ByteOrder.LITTLE_ENDIAN);
2442+
ByteBuffer buffer = ByteBuffer.wrap(src).order(ByteOrder.LITTLE_ENDIAN);
24412443

24422444
for (; pData < pLast; pData += 32) {
24432445
long b0 = buffer.getLong(pData) ^ uCrc0;
@@ -2515,7 +2517,7 @@ public static long compute(byte[] src, int offset, int length, long uCrc) {
25152517
}
25162518

25172519
uCrc = 0;
2518-
uCrc ^= ByteBuffer.wrap(src, offset + pData, 8).order(ByteOrder.LITTLE_ENDIAN).getLong() ^ uCrc0;
2520+
uCrc ^= ByteBuffer.wrap(src, pData, 8).order(ByteOrder.LITTLE_ENDIAN).getLong() ^ uCrc0;
25192521
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
25202522
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
25212523
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
@@ -2525,7 +2527,7 @@ public static long compute(byte[] src, int offset, int length, long uCrc) {
25252527
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
25262528
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
25272529

2528-
uCrc ^= ByteBuffer.wrap(src, offset + pData + 8, 8).order(ByteOrder.LITTLE_ENDIAN).getLong() ^ uCrc1;
2530+
uCrc ^= ByteBuffer.wrap(src, pData + 8, 8).order(ByteOrder.LITTLE_ENDIAN).getLong() ^ uCrc1;
25292531
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
25302532
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
25312533
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
@@ -2535,7 +2537,7 @@ public static long compute(byte[] src, int offset, int length, long uCrc) {
25352537
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
25362538
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
25372539

2538-
uCrc ^= ByteBuffer.wrap(src, offset + pData + 16, 8).order(ByteOrder.LITTLE_ENDIAN).getLong() ^ uCrc2;
2540+
uCrc ^= ByteBuffer.wrap(src, pData + 16, 8).order(ByteOrder.LITTLE_ENDIAN).getLong() ^ uCrc2;
25392541
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
25402542
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
25412543
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
@@ -2545,7 +2547,7 @@ public static long compute(byte[] src, int offset, int length, long uCrc) {
25452547
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
25462548
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
25472549

2548-
uCrc ^= ByteBuffer.wrap(src, offset + pData + 24, 8).order(ByteOrder.LITTLE_ENDIAN).getLong() ^ uCrc3;
2550+
uCrc ^= ByteBuffer.wrap(src, pData + 24, 8).order(ByteOrder.LITTLE_ENDIAN).getLong() ^ uCrc3;
25492551
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
25502552
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
25512553
uCrc = (uCrc >>> 8) ^ M_U1[(int) (uCrc & 0xFF)];
@@ -2559,7 +2561,7 @@ public static long compute(byte[] src, int offset, int length, long uCrc) {
25592561
}
25602562

25612563
for (uBytes = 0; uBytes < uSize; ++uBytes, ++pData) {
2562-
uCrc = (uCrc >>> 8) ^ M_U1[(int) ((uCrc ^ src[offset + pData]) & 0xFF)];
2564+
uCrc = (uCrc >>> 8) ^ M_U1[(int) ((uCrc ^ src[pData]) & 0xFF)];
25632565
}
25642566

25652567
return ~uCrc;

sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/contentvalidation/StructuredMessageDecodingStream.java

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)