|
14 | 14 | */
|
15 | 15 | package com.microsoft.azure.storage.blob;
|
16 | 16 |
|
17 |
| -import com.microsoft.azure.storage.blob.models.AppendBlobAppendBlockResponse; |
18 |
| -import com.microsoft.azure.storage.blob.models.AppendBlobCreateResponse; |
19 |
| -import com.microsoft.azure.storage.blob.models.BlobHTTPHeaders; |
| 17 | +import com.microsoft.azure.storage.blob.models.*; |
20 | 18 | import com.microsoft.rest.v2.Context;
|
21 | 19 | import com.microsoft.rest.v2.http.HttpPipeline;
|
22 | 20 | import io.reactivex.Flowable;
|
|
27 | 25 | import java.net.UnknownHostException;
|
28 | 26 | import java.nio.ByteBuffer;
|
29 | 27 |
|
30 |
| -import static com.microsoft.azure.storage.blob.Utility.addErrorWrappingToSingle; |
| 28 | +import static com.microsoft.azure.storage.blob.Utility.postProcessResponse; |
31 | 29 |
|
32 | 30 |
|
33 | 31 | /**
|
@@ -132,11 +130,11 @@ public Single<AppendBlobCreateResponse> create() {
|
132 | 130 | */
|
133 | 131 | public Single<AppendBlobCreateResponse> create(BlobHTTPHeaders headers, Metadata metadata,
|
134 | 132 | BlobAccessConditions accessConditions, Context context) {
|
135 |
| - metadata = metadata == null ? Metadata.NONE : metadata; |
136 |
| - accessConditions = accessConditions == null ? BlobAccessConditions.NONE : accessConditions; |
| 133 | + metadata = metadata == null ? new Metadata() : metadata; |
| 134 | + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; |
137 | 135 | context = context == null ? Context.NONE : context;
|
138 | 136 |
|
139 |
| - return addErrorWrappingToSingle(this.storageClient.generatedAppendBlobs().createWithRestResponseAsync(context, |
| 137 | + return postProcessResponse(this.storageClient.generatedAppendBlobs().createWithRestResponseAsync(context, |
140 | 138 | 0, null, metadata, null, headers, accessConditions.leaseAccessConditions(),
|
141 | 139 | accessConditions.modifiedAccessConditions()));
|
142 | 140 | }
|
@@ -195,15 +193,88 @@ public Single<AppendBlobAppendBlockResponse> appendBlock(Flowable<ByteBuffer> da
|
195 | 193 | */
|
196 | 194 | public Single<AppendBlobAppendBlockResponse> appendBlock(Flowable<ByteBuffer> data, long length,
|
197 | 195 | AppendBlobAccessConditions appendBlobAccessConditions, Context context) {
|
198 |
| - appendBlobAccessConditions = appendBlobAccessConditions == null ? AppendBlobAccessConditions.NONE : |
| 196 | + appendBlobAccessConditions = appendBlobAccessConditions == null ? new AppendBlobAccessConditions() : |
199 | 197 | appendBlobAccessConditions;
|
200 | 198 | appendBlobAccessConditions = appendBlobAccessConditions == null
|
201 |
| - ? AppendBlobAccessConditions.NONE : appendBlobAccessConditions; |
| 199 | + ? new AppendBlobAccessConditions() : appendBlobAccessConditions; |
202 | 200 | context = context == null ? Context.NONE : context;
|
203 | 201 |
|
204 |
| - return addErrorWrappingToSingle(this.storageClient.generatedAppendBlobs().appendBlockWithRestResponseAsync( |
| 202 | + return postProcessResponse(this.storageClient.generatedAppendBlobs().appendBlockWithRestResponseAsync( |
205 | 203 | context, data, length, null, null, null, appendBlobAccessConditions.leaseAccessConditions(),
|
206 | 204 | appendBlobAccessConditions.appendPositionAccessConditions(),
|
207 | 205 | appendBlobAccessConditions.modifiedAccessConditions()));
|
208 | 206 | }
|
| 207 | + |
| 208 | + /** |
| 209 | + * Commits a new block of data from another blob to the end of this append blob. For more information, see the |
| 210 | + * <a href="https://docs.microsoft.com/rest/api/storageservices/append-block">Azure Docs</a>. |
| 211 | + * <p> |
| 212 | + * |
| 213 | + * @param sourceURL |
| 214 | + * The url to the blob that will be the source of the copy. A source blob in the same storage account can |
| 215 | + * be authenticated via Shared Key. However, if the source is a blob in another account, the source blob |
| 216 | + * must either be public or must be authenticated via a shared access signature. If the source blob is |
| 217 | + * public, no authentication is required to perform the operation. |
| 218 | + * @param sourceRange |
| 219 | + * The source {@link BlobRange} to copy. |
| 220 | + * |
| 221 | + * @return Emits the successful response. |
| 222 | + * |
| 223 | + * @apiNote ## Sample Code \n |
| 224 | + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=append_from_url "Sample code for AppendBlobURL.appendBlockFromUrl")] |
| 225 | + * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) |
| 226 | + */ |
| 227 | + public Single<AppendBlobAppendBlockFromUrlResponse> appendBlockFromUrl(URL sourceURL, BlobRange sourceRange) { |
| 228 | + return this.appendBlockFromUrl(sourceURL, sourceRange, null, null, |
| 229 | + null, null); |
| 230 | + } |
| 231 | + |
| 232 | + /** |
| 233 | + * Commits a new block of data from another blob to the end of this append blob. For more information, see the |
| 234 | + * <a href="https://docs.microsoft.com/rest/api/storageservices/append-block">Azure Docs</a>. |
| 235 | + * <p> |
| 236 | + * |
| 237 | + * @param sourceURL |
| 238 | + * The url to the blob that will be the source of the copy. A source blob in the same storage account can |
| 239 | + * be authenticated via Shared Key. However, if the source is a blob in another account, the source blob |
| 240 | + * must either be public or must be authenticated via a shared access signature. If the source blob is |
| 241 | + * public, no authentication is required to perform the operation. |
| 242 | + * @param sourceRange |
| 243 | + * {@link BlobRange} |
| 244 | + * @param sourceContentMD5 |
| 245 | + * An MD5 hash of the block content from the source blob. If specified, the service will calculate the MD5 |
| 246 | + * of the received data and fail the request if it does not match the provided MD5. |
| 247 | + * @param destAccessConditions |
| 248 | + * {@link AppendBlobAccessConditions} |
| 249 | + * @param sourceAccessConditions |
| 250 | + * {@link SourceModifiedAccessConditions} |
| 251 | + * @param context |
| 252 | + * {@code Context} offers a means of passing arbitrary data (key/value pairs) to an |
| 253 | + * {@link com.microsoft.rest.v2.http.HttpPipeline}'s policy objects. Most applications do not need to pass |
| 254 | + * arbitrary data to the pipeline and can pass {@code Context.NONE} or {@code null}. Each context object is |
| 255 | + * immutable. The {@code withContext} with data method creates a new {@code Context} object that refers to |
| 256 | + * its parent, forming a linked list. |
| 257 | + * |
| 258 | + * @return Emits the successful response. |
| 259 | + * |
| 260 | + * @apiNote ## Sample Code \n |
| 261 | + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=append_from_url "Sample code for AppendBlobURL.appendBlockFromUrl")] |
| 262 | + * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) |
| 263 | + */ |
| 264 | + public Single<AppendBlobAppendBlockFromUrlResponse> appendBlockFromUrl(URL sourceURL, BlobRange sourceRange, |
| 265 | + byte[] sourceContentMD5, AppendBlobAccessConditions destAccessConditions, |
| 266 | + SourceModifiedAccessConditions sourceAccessConditions, Context context) { |
| 267 | + |
| 268 | + sourceRange = sourceRange == null ? new BlobRange() : sourceRange; |
| 269 | + destAccessConditions = destAccessConditions == null |
| 270 | + ? new AppendBlobAccessConditions() : destAccessConditions; |
| 271 | + context = context == null ? Context.NONE : context; |
| 272 | + |
| 273 | + return postProcessResponse( |
| 274 | + this.storageClient.generatedAppendBlobs().appendBlockFromUrlWithRestResponseAsync(context, |
| 275 | + sourceURL, 0, sourceRange.toString(), sourceContentMD5, null, null, |
| 276 | + destAccessConditions.leaseAccessConditions(), |
| 277 | + destAccessConditions.appendPositionAccessConditions(), |
| 278 | + destAccessConditions.modifiedAccessConditions(), sourceAccessConditions)); |
| 279 | + } |
209 | 280 | }
|
0 commit comments