/** * Writes a blob by specifying the list of block IDs that are to make up the blob. * In order to be written as part of a blob, a block must have been successfully written * to the server in a prior stageBlock operation. You can call commitBlockList to update a blob * by uploading only those blocks that have changed, then committing the new and existing * blocks together. Any blocks not specified in the block list and permanently deleted. * For more information, see the * <a href="https://docs.microsoft.com/rest/api/storageservices/put-block-list">Azure Docs</a>. * <p> * For more efficient bulk-upload scenarios, please refer to the {@link TransferManager} for convenience methods. * * @param base64BlockIDs * A list of base64 encode {@code String}s that specifies the block IDs to be committed. * * @return Emits the successful response. * * @apiNote ## Sample Code \n * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobURL.commitBlockList")] \n * 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) */ public Single<BlockBlobCommitBlockListResponse> commitBlockList(List<String> base64BlockIDs) { return this.commitBlockList(base64BlockIDs, null, null, null, null); }
/** * Returns the list of blocks that have been uploaded as part of a block blob using the specified block list filter. * For more information, see the * <a href="https://docs.microsoft.com/rest/api/storageservices/get-block-list">Azure Docs</a>. * * @param listType * Specifies which type of blocks to return. * * @return Emits the successful response. * * @apiNote ## Sample Code \n * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobURL.getBlockList")] \n * 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) */ public Single<BlockBlobGetBlockListResponse> getBlockList(BlockListType listType) { return this.getBlockList(listType, null, null); }
/** * Uploads the specified block to the block blob's "staging area" to be later committed by a call to * commitBlockList. For more information, see the * <a href="https://docs.microsoft.com/rest/api/storageservices/put-block">Azure Docs</a>. * <p> * Note that the data passed must be replayable if retries are enabled (the default). In other words, the * {@code Flowable} must produce the same data each time it is subscribed to. * * @param base64BlockID * A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given * blob must be the same length. * @param data * The data to write to the block. Note that this {@code Flowable} must be replayable if retries are enabled * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. * @param length * The exact length of the data. It is important that this value match precisely the length of the data * emitted by the {@code Flowable}. * * @return Emits the successful response. * * @apiNote ## Sample Code \n * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobURL.stageBlock")] \n * 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) */ public Single<BlockBlobStageBlockResponse> stageBlock(String base64BlockID, Flowable<ByteBuffer> data, long length) { return this.stageBlock(base64BlockID, data, length, null, null); }
return blockBlobURL.upload(data, file.size(), optionsReal.httpHeaders(), optionsReal.metadata(), optionsReal.accessConditions(), null) return blockBlobURL.stageBlock(blockId, data, count, optionsReal.accessConditions().leaseAccessConditions(), null) .map(x -> blockId).toObservable(); blockBlobURL.commitBlockList(ids, optionsReal.httpHeaders(), optionsReal.metadata(), optionsReal.accessConditions(), null))
/** * Creates a new {@link BlockBlobURL} with the given pipeline. * * @param pipeline * An {@link HttpPipeline} object to set. * * @return A {@link BlockBlobURL} object with the given pipeline. */ public BlockBlobURL withPipeline(HttpPipeline pipeline) { try { return new BlockBlobURL(new URL(this.storageClient.url()), pipeline); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
public static void deleteBlob(BlockBlobURL blockBlobURL) { logInfo("Start deleting file %s...", blockBlobURL.toURL()); blockBlobURL.delete(null, null, null) .toCompletable() .doOnComplete(() -> logInfo("Blob %s is deleted.", blockBlobURL.toURL())) .doOnError(error -> logError("Failed to delete blob %s with error %s.", blockBlobURL.toURL(), error.getMessage())) .blockingAwait(); }
public static void downloadBlob(BlockBlobURL blockBlobURL, File downloadToFile) { logInfo("Start downloading file %s to %s...", blockBlobURL.toURL(), downloadToFile); FileUtils.deleteQuietly(downloadToFile); blockBlobURL.download(new BlobRange().withOffset(0).withCount(4 * 1024 * 1024L), null, false, null) .flatMapCompletable( response -> { final AsynchronousFileChannel channel = AsynchronousFileChannel .open(Paths.get(downloadToFile.getAbsolutePath()), StandardOpenOption.CREATE, StandardOpenOption.WRITE); return FlowableUtil.writeFile(response.body(null), channel); }) .doOnComplete(() -> logInfo("File is downloaded to %s.", downloadToFile)) .doOnError(error -> logError("Failed to download file from blob %s with error %s.", blockBlobURL.toURL(), error.getMessage())) .blockingAwait(); }
/** * Creates a new block to be committed as part of a blob where the contents are read from a URL. For more * information, see the <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/put-block-from-url">Azure Docs</a>. * * @param base64BlockID * A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given * blob must be the same length. * @param sourceURL * The url to the blob that will be the source of the copy. A source blob in the same storage account can be * authenticated via Shared Key. However, if the source is a blob in another account, the source blob must * either be public or must be authenticated via a shared access signature. If the source blob is public, no * authentication is required to perform the operation. * @param sourceRange * {@link BlobRange} * * @return Emits the successful response. * * @apiNote ## Sample Code \n * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=block_from_url "Sample code for BlockBlobURL.stageBlockFromURL")] * 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) */ public Single<BlockBlobStageBlockFromURLResponse> stageBlockFromURL(String base64BlockID, URL sourceURL, BlobRange sourceRange) { return this.stageBlockFromURL(base64BlockID, sourceURL, sourceRange, null, null, null); }
/** * Creates a new block blob, or updates the content of an existing block blob. * Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not * supported with PutBlob; the content of the existing blob is overwritten with the new content. To * perform a partial update of a block blob's, use PutBlock and PutBlockList. * For more information, see the * <a href="https://docs.microsoft.com/rest/api/storageservices/put-blob">Azure Docs</a>. * <p> * Note that the data passed must be replayable if retries are enabled (the default). In other words, the * {@code Flowable} must produce the same data each time it is subscribed to. * <p> * For more efficient bulk-upload scenarios, please refer to the {@link TransferManager} for convenience methods. * * @param data * The data to write to the blob. Note that this {@code Flowable} must be replayable if retries are enabled * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. * @param length * The exact length of the data. It is important that this value match precisely the length of the data * emitted by the {@code Flowable}. * * @return Emits the successful response. * * @apiNote ## Sample Code \n * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=upload_download "Sample code for BlockBlobURL.upload")] \n * 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) */ public Single<BlockBlobUploadResponse> upload(Flowable<ByteBuffer> data, long length) { return this.upload(data, length, null, null, null, null); }
return blockBlobURL.upload(data, file.size(), optionsReal.httpHeaders(), optionsReal.metadata(), optionsReal.accessConditions(), null) return blockBlobURL.stageBlock(blockId, data, count, optionsReal.accessConditions().leaseAccessConditions(), null) .map(x -> blockId).toObservable(); blockBlobURL.commitBlockList(ids, optionsReal.httpHeaders(), optionsReal.metadata(), optionsReal.accessConditions(), null))
/** * Creates a new {@link BlockBlobURL} with the given pipeline. * * @param pipeline * An {@link HttpPipeline} object to set. * * @return A {@link BlockBlobURL} object with the given pipeline. */ public BlockBlobURL withPipeline(HttpPipeline pipeline) { try { return new BlockBlobURL(new URL(this.storageClient.url()), pipeline); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
/** * Creates a new block to be committed as part of a blob where the contents are read from a URL. For more * information, see the <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/put-block-from-url">Azure Docs</a>. * * @param base64BlockID * A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given * blob must be the same length. * @param sourceURL * The url to the blob that will be the source of the copy. A source blob in the same storage account can be * authenticated via Shared Key. However, if the source is a blob in another account, the source blob must * either be public or must be authenticated via a shared access signature. If the source blob is public, no * authentication is required to perform the operation. * @param sourceRange * {@link BlobRange} * * @return Emits the successful response. * * @apiNote ## Sample Code \n * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=block_from_url "Sample code for BlockBlobURL.stageBlockFromURL")] * 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) */ public Single<BlockBlobStageBlockFromURLResponse> stageBlockFromURL(String base64BlockID, URL sourceURL, BlobRange sourceRange) { return this.stageBlockFromURL(base64BlockID, sourceURL, sourceRange, null, null, null); }
/** * Creates a new block blob, or updates the content of an existing block blob. * Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not * supported with PutBlob; the content of the existing blob is overwritten with the new content. To * perform a partial update of a block blob's, use PutBlock and PutBlockList. * For more information, see the * <a href="https://docs.microsoft.com/rest/api/storageservices/put-blob">Azure Docs</a>. * <p> * Note that the data passed must be replayable if retries are enabled (the default). In other words, the * {@code Flowable} must produce the same data each time it is subscribed to. * <p> * For more efficient bulk-upload scenarios, please refer to the {@link TransferManager} for convenience methods. * * @param data * The data to write to the blob. Note that this {@code Flowable} must be replayable if retries are enabled * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. * @param length * The exact length of the data. It is important that this value match precisely the length of the data * emitted by the {@code Flowable}. * * @return Emits the successful response. * * @apiNote ## Sample Code \n * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=upload_download "Sample code for BlockBlobURL.upload")] \n * 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) */ public Single<BlockBlobUploadResponse> upload(Flowable<ByteBuffer> data, long length) { return this.upload(data, length, null, null, null, null); }
/** * Converts this BlobURL to a {@link BlockBlobURL} object. Note that this does not change the actual type of the * blob if it has already been created. * * @return A {@link BlockBlobURL} object. */ public BlockBlobURL toBlockBlobURL() { try { return new BlockBlobURL(new URL(this.storageClient.url()), super.storageClient.httpPipeline()); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
/** * Returns the list of blocks that have been uploaded as part of a block blob using the specified block list filter. * For more information, see the * <a href="https://docs.microsoft.com/rest/api/storageservices/get-block-list">Azure Docs</a>. * * @param listType * Specifies which type of blocks to return. * * @return Emits the successful response. * * @apiNote ## Sample Code \n * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobURL.getBlockList")] \n * 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) */ public Single<BlockBlobGetBlockListResponse> getBlockList(BlockListType listType) { return this.getBlockList(listType, null, null); }
/** * Writes a blob by specifying the list of block IDs that are to make up the blob. * In order to be written as part of a blob, a block must have been successfully written * to the server in a prior stageBlock operation. You can call commitBlockList to update a blob * by uploading only those blocks that have changed, then committing the new and existing * blocks together. Any blocks not specified in the block list and permanently deleted. * For more information, see the * <a href="https://docs.microsoft.com/rest/api/storageservices/put-block-list">Azure Docs</a>. * <p> * For more efficient bulk-upload scenarios, please refer to the {@link TransferManager} for convenience methods. * * @param base64BlockIDs * A list of base64 encode {@code String}s that specifies the block IDs to be committed. * * @return Emits the successful response. * * @apiNote ## Sample Code \n * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobURL.commitBlockList")] \n * 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) */ public Single<BlockBlobCommitBlockListResponse> commitBlockList(List<String> base64BlockIDs) { return this.commitBlockList(base64BlockIDs, null, null, null, null); }
/** * Uploads the specified block to the block blob's "staging area" to be later committed by a call to * commitBlockList. For more information, see the * <a href="https://docs.microsoft.com/rest/api/storageservices/put-block">Azure Docs</a>. * <p> * Note that the data passed must be replayable if retries are enabled (the default). In other words, the * {@code Flowable} must produce the same data each time it is subscribed to. * * @param base64BlockID * A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given * blob must be the same length. * @param data * The data to write to the block. Note that this {@code Flowable} must be replayable if retries are enabled * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. * @param length * The exact length of the data. It is important that this value match precisely the length of the data * emitted by the {@code Flowable}. * * @return Emits the successful response. * * @apiNote ## Sample Code \n * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobURL.stageBlock")] \n * 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) */ public Single<BlockBlobStageBlockResponse> stageBlock(String base64BlockID, Flowable<ByteBuffer> data, long length) { return this.stageBlock(base64BlockID, data, length, null, null); }
/** * Converts this BlobURL to a {@link BlockBlobURL} object. Note that this does not change the actual type of the * blob if it has already been created. * * @return A {@link BlockBlobURL} object. */ public BlockBlobURL toBlockBlobURL() { try { return new BlockBlobURL(new URL(this.storageClient.url()), super.storageClient.httpPipeline()); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
/** * Creates a new {@link BlockBlobURL} object by concatenating the blobName to the end of * ContainerURL's URL. The new BlockBlobUrl uses the same request policy pipeline as the ContainerURL. * To change the pipeline, create the BlockBlobUrl and then call its WithPipeline method passing in the * desired pipeline object. Or, call this package's NewBlockBlobUrl instead of calling this object's * NewBlockBlobUrl method. * * @param blobName * A {@code String} representing the name of the blob. * * @return A new {@link BlockBlobURL} object which references the blob with the specified name in this container. */ public BlockBlobURL createBlockBlobURL(String blobName) { blobName = safeURLEncode(blobName); try { return new BlockBlobURL(StorageURL.appendToURLPath(new URL(this.storageClient.url()), blobName), this.storageClient.httpPipeline()); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
/** * Creates a new {@link BlockBlobURL} object by concatenating the blobName to the end of * ContainerURL's URL. The new BlockBlobUrl uses the same request policy pipeline as the ContainerURL. * To change the pipeline, create the BlockBlobUrl and then call its WithPipeline method passing in the * desired pipeline object. Or, call this package's NewBlockBlobUrl instead of calling this object's * NewBlockBlobUrl method. * * @param blobName * A {@code String} representing the name of the blob. * * @return A new {@link BlockBlobURL} object which references the blob with the specified name in this container. */ public BlockBlobURL createBlockBlobURL(String blobName) { blobName = safeURLEncode(blobName); try { return new BlockBlobURL(StorageURL.appendToURLPath(new URL(this.storageClient.url()), blobName), this.storageClient.httpPipeline()); } catch (MalformedURLException e) { throw new RuntimeException(e); } }