-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support to specify block size in BlobInputStream #15496
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.storage.blob.options; | ||
|
||
import com.azure.core.annotation.Fluent; | ||
import com.azure.storage.blob.models.BlobRange; | ||
import com.azure.storage.blob.models.BlobRequestConditions; | ||
|
||
/** | ||
* Extended options that may be passed when opening a blob input stream. | ||
*/ | ||
@Fluent | ||
public class BlobInputStreamOptions { | ||
|
||
private BlobRange range; | ||
private BlobRequestConditions requestConditions; | ||
private Integer blockSize; | ||
|
||
/** | ||
* @return {@link BlobRange} | ||
*/ | ||
public BlobRange getRange() { | ||
return range; | ||
} | ||
|
||
/** | ||
* @param range {@link BlobRange} | ||
* @return The updated options. | ||
*/ | ||
public BlobInputStreamOptions setRange(BlobRange range) { | ||
this.range = range; | ||
return this; | ||
} | ||
|
||
/** | ||
* @return {@link BlobRequestConditions} | ||
*/ | ||
public BlobRequestConditions getRequestConditions() { | ||
return requestConditions; | ||
} | ||
|
||
/** | ||
* @param requestConditions {@link BlobRequestConditions} | ||
* @return The updated options. | ||
*/ | ||
public BlobInputStreamOptions setRequestConditions(BlobRequestConditions requestConditions) { | ||
this.requestConditions = requestConditions; | ||
return this; | ||
} | ||
|
||
/** | ||
* @return The size of each data chunk returned from the service. If block size is large, input stream will make | ||
* fewer network calls, but each individual call will send more data and will therefore take longer. | ||
* The default value is 4 MB. | ||
*/ | ||
public Integer getBlockSize() { | ||
return blockSize; | ||
} | ||
|
||
/** | ||
* @param blockSize The size of each data chunk returned from the service. If block size is large, input stream | ||
* will make fewer network calls, but each individual call will send more data and will therefore take longer. | ||
* The default value is 4 MB. | ||
* @return The updated options. | ||
*/ | ||
public BlobInputStreamOptions setBlockSize(Integer blockSize) { | ||
this.blockSize = blockSize; | ||
return this; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import com.azure.storage.blob.models.BlobQueryAsyncResponse; | ||
import com.azure.storage.blob.options.BlobDownloadToFileOptions; | ||
import com.azure.storage.blob.options.BlobGetTagsOptions; | ||
import com.azure.storage.blob.options.BlobInputStreamOptions; | ||
import com.azure.storage.blob.options.BlobQueryOptions; | ||
import com.azure.storage.blob.models.BlobQueryResponse; | ||
import com.azure.storage.blob.models.BlobRange; | ||
|
@@ -41,6 +42,7 @@ | |
import com.azure.storage.blob.options.BlobSetTagsOptions; | ||
import com.azure.storage.blob.sas.BlobServiceSasSignatureValues; | ||
import com.azure.storage.common.StorageSharedKeyCredential; | ||
import com.azure.storage.common.implementation.Constants; | ||
import com.azure.storage.common.implementation.FluxInputStream; | ||
import com.azure.storage.common.implementation.StorageImplUtils; | ||
import reactor.core.Exceptions; | ||
|
@@ -219,7 +221,7 @@ public boolean isSnapshot() { | |
* @throws BlobStorageException If a storage service error occurred. | ||
*/ | ||
public final BlobInputStream openInputStream() { | ||
return openInputStream(new BlobRange(0), null); | ||
return openInputStream(null, null); | ||
} | ||
|
||
/** | ||
|
@@ -233,7 +235,23 @@ public final BlobInputStream openInputStream() { | |
* @throws BlobStorageException If a storage service error occurred. | ||
*/ | ||
public final BlobInputStream openInputStream(BlobRange range, BlobRequestConditions requestConditions) { | ||
return new BlobInputStream(client, range.getOffset(), range.getCount(), requestConditions); | ||
return openInputStream(new BlobInputStreamOptions().setRange(range).setRequestConditions(requestConditions)); | ||
} | ||
|
||
/** | ||
* Opens a blob input stream to download the specified range of the blob. | ||
* | ||
* @param options {@link BlobInputStreamOptions} | ||
* @return An <code>InputStream</code> object that represents the stream to use for reading from the blob. | ||
* @throws BlobStorageException If a storage service error occurred. | ||
*/ | ||
public BlobInputStream openInputStream(BlobInputStreamOptions options) { | ||
options = options == null ? new BlobInputStreamOptions() : options; | ||
BlobRange range = options.getRange() == null ? new BlobRange(0) : options.getRange(); | ||
int chunkSize = options.getBlockSize() == null ? 4 * Constants.MB : options.getBlockSize(); | ||
|
||
return new BlobInputStream(client, range.getOffset(), range.getCount(), chunkSize, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is a minor change where we will make an additional service call to get the properties of the blob before opening the stream. Are we okay with that? If so, we should add a quick document stating that we will be doing this as it is a behavioral change from the past. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I think we already called getProperties before, I just moved it outside since we can't call it in the constructor before a call to super |
||
options.getRequestConditions(), getProperties()); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are going to say the default if
4 MB
should the getter check forblockSize == null
and return4 * Constants.MB
?If this change is made, we could also change the return type to
int
instead ofInteger
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we tie this type to promising that? I'm a little hesitant to do that. I'd prefer it just be normal fluent behavior