你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
PageBlobClient Class
- java.
lang. Object - com.
azure. storage. blob. specialized. BlobClientBase - com.
azure. storage. blob. specialized. PageBlobClient
- com.
- com.
public final class PageBlobClient
extends BlobClientBase
Client to a page blob. It may only be instantiated through a SpecializedBlobClientBuilder or via the method getPageBlobClient(). This class does not hold any state about a particular blob, but is instead a convenient way of sending appropriate requests to the resource on the service.
Please refer to the Azure Docs for more information.
Field Summary
Modifier and Type | Field and Description |
---|---|
static final int |
MAX_PUT_PAGES_BYTES
Indicates the maximum number of bytes that may be sent in a call to put |
static final int |
PAGE_BYTES
Indicates the number of bytes in a page. |
Method Summary
Methods inherited from BlobClientBase
Methods inherited from java.lang.Object
Field Details
MAX_PUT_PAGES_BYTES
public static final int MAX_PUT_PAGES_BYTES
Indicates the maximum number of bytes that may be sent in a call to putPage.
PAGE_BYTES
public static final int PAGE_BYTES
Indicates the number of bytes in a page.
Method Details
clearPages
public PageBlobItem clearPages(PageRange pageRange)
Frees the specified pages from the page blob. The size of the range must be a multiple of 512. For more information, see the Azure Docs.
Code Samples
PageRange pageRange = new PageRange()
.setStart(0)
.setEnd(511);
PageBlobItem pageBlob = client.clearPages(pageRange);
System.out.printf("Cleared page blob with sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
clearPagesWithResponse
public Response
Frees the specified pages from the page blob. The size of the range must be a multiple of 512. For more information, see the Azure Docs.
Code Samples
PageRange pageRange = new PageRange()
.setStart(0)
.setEnd(511);
PageBlobRequestConditions pageBlobRequestConditions = new PageBlobRequestConditions().setLeaseId(leaseId);
Context context = new Context(key, value);
PageBlobItem pageBlob = client
.clearPagesWithResponse(pageRange, pageBlobRequestConditions, timeout, context).getValue();
System.out.printf("Cleared page blob with sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
copyIncremental
public CopyStatusType copyIncremental(String source, String snapshot)
Begins an operation to start an incremental copy from one page blob's snapshot to this page blob. The snapshot is copied such that only the differential changes between the previously copied snapshot are transferred to the destination. The copied snapshots are complete copies of the original snapshot and can be read or copied from as usual. For more information, see the Azure Docs here and here.
Code Samples
final String snapshot = "copy snapshot";
CopyStatusType statusType = client.copyIncremental(url, snapshot);
switch (statusType) {
case SUCCESS:
System.out.println("Page blob copied successfully");
break;
case FAILED:
System.out.println("Page blob copied failed");
break;
case ABORTED:
System.out.println("Page blob copied aborted");
break;
case PENDING:
System.out.println("Page blob copied pending");
break;
default:
break;
}
Parameters:
Returns:
copyIncrementalWithResponse
public Response
Begins an operation to start an incremental copy from one page blob's snapshot to this page blob. The snapshot is copied such that only the differential changes between the previously copied snapshot are transferred to the destination. The copied snapshots are complete copies of the original snapshot and can be read or copied from as usual. For more information, see the Azure Docs here and here.
Code Samples
final String snapshot = "copy snapshot";
PageBlobCopyIncrementalRequestConditions destinationRequestConditions = new PageBlobCopyIncrementalRequestConditions()
.setIfNoneMatch("snapshotMatch");
Context context = new Context(key, value);
CopyStatusType statusType = client
.copyIncrementalWithResponse(new PageBlobCopyIncrementalOptions(url, snapshot)
.setRequestConditions(destinationRequestConditions), timeout, context).getValue();
switch (statusType) {
case SUCCESS:
System.out.println("Page blob copied successfully");
break;
case FAILED:
System.out.println("Page blob copied failed");
break;
case ABORTED:
System.out.println("Page blob copied aborted");
break;
case PENDING:
System.out.println("Page blob copied pending");
break;
default:
break;
}
Parameters:
Returns:
copyIncrementalWithResponse
public Response
Begins an operation to start an incremental copy from one page blob's snapshot to this page blob. The snapshot is copied such that only the differential changes between the previously copied snapshot are transferred to the destination. The copied snapshots are complete copies of the original snapshot and can be read or copied from as usual. For more information, see the Azure Docs here and here.
Code Samples
final String snapshot = "copy snapshot";
RequestConditions modifiedRequestConditions = new RequestConditions()
.setIfNoneMatch("snapshotMatch");
Context context = new Context(key, value);
CopyStatusType statusType = client
.copyIncrementalWithResponse(url, snapshot, modifiedRequestConditions, timeout, context).getValue();
switch (statusType) {
case SUCCESS:
System.out.println("Page blob copied successfully");
break;
case FAILED:
System.out.println("Page blob copied failed");
break;
case ABORTED:
System.out.println("Page blob copied aborted");
break;
case PENDING:
System.out.println("Page blob copied pending");
break;
default:
break;
}
Parameters:
Returns:
create
public PageBlobItem create(long size)
Creates a page blob of the specified length. By default this method will not overwrite an existing blob. Call PutPage to upload data data to a page blob. For more information, see the Azure Docs.
Code Samples
PageBlobItem pageBlob = client.create(size);
System.out.printf("Created page blob with sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
create
public PageBlobItem create(long size, boolean overwrite)
Creates a page blob of the specified length. Call PutPage to upload data data to a page blob. For more information, see the Azure Docs.
Code Samples
boolean overwrite = false; // Default value
PageBlobItem pageBlob = client.create(size, overwrite);
System.out.printf("Created page blob with sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
createIfNotExists
public PageBlobItem createIfNotExists(long size)
Creates a page blob of the specified length if it does not exist. Call PutPage to upload data to a page blob. For more information, see the Azure Docs.
Code Samples
PageBlobItem pageBlob = client.createIfNotExists(size);
System.out.printf("Created page blob with sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
createIfNotExistsWithResponse
public Response
Creates a page blob of the specified length if it does not exist. Call PutPage to upload data to a page blob. For more information, see the Azure Docs.
Code Samples
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentLanguage("en-US")
.setContentType("binary");
Context context = new Context(key, value);
Response<PageBlobItem> response = client.createIfNotExistsWithResponse(new PageBlobCreateOptions(size)
.setHeaders(headers).setMetadata(metadata).setTags(tags), timeout, context);
if (response.getStatusCode() == 409) {
System.out.println("Already existed.");
} else {
System.out.printf("Create completed with status %d%n", response.getStatusCode());
}
Parameters:
Returns:
createWithResponse
public Response
Creates a page blob of the specified length. Call PutPage to upload data data to a page blob. For more information, see the Azure Docs.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Code Samples
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentLanguage("en-US")
.setContentType("binary");
BlobRequestConditions blobRequestConditions = new BlobRequestConditions().setLeaseId(leaseId);
Context context = new Context(key, value);
PageBlobItem pageBlob = client
.createWithResponse(new PageBlobCreateOptions(size).setSequenceNumber(sequenceNumber)
.setHeaders(headers).setMetadata(metadata).setTags(tags)
.setRequestConditions(blobRequestConditions), timeout,
context)
.getValue();
System.out.printf("Created page blob with sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
createWithResponse
public Response
Creates a page blob of the specified length. Call PutPage to upload data data to a page blob. For more information, see the Azure Docs.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Code Samples
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentLanguage("en-US")
.setContentType("binary");
BlobRequestConditions blobRequestConditions = new BlobRequestConditions().setLeaseId(leaseId);
Context context = new Context(key, value);
PageBlobItem pageBlob = client
.createWithResponse(size, sequenceNumber, headers, metadata, blobRequestConditions, timeout, context)
.getValue();
System.out.printf("Created page blob with sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
getBlobOutputStream
public BlobOutputStream getBlobOutputStream(PageRange pageRange)
Creates and opens an output stream to write data to the page blob. If the blob already exists on the service, it will be overwritten.
Parameters:
Returns:
getBlobOutputStream
public BlobOutputStream getBlobOutputStream(PageRange pageRange, BlobRequestConditions requestConditions)
Creates and opens an output stream to write data to the page blob. If the blob already exists on the service, it will be overwritten.
Parameters:
Returns:
getCustomerProvidedKeyClient
public PageBlobClient getCustomerProvidedKeyClient(CustomerProvidedKey customerProvidedKey)
Creates a new PageBlobClient with the specified customerProvidedKey
.
Overrides:
PageBlobClient.getCustomerProvidedKeyClient(CustomerProvidedKey customerProvidedKey)Parameters:
null
to use no customer provided key.
Returns:
customerProvidedKey
.getEncryptionScopeClient
public PageBlobClient getEncryptionScopeClient(String encryptionScope)
Creates a new PageBlobClient with the specified encryptionScope
.
Overrides:
PageBlobClient.getEncryptionScopeClient(String encryptionScope)Parameters:
null
to use no encryption scope.
Returns:
encryptionScope
.getManagedDiskPageRangesDiff
public PageList getManagedDiskPageRangesDiff(BlobRange blobRange, String prevSnapshotUrl)
This API only works for managed disk accounts.
Gets the collection of page ranges that differ between a specified snapshot and this page blob. For more information, see the Azure Docs.
Code Samples
BlobRange blobRange = new BlobRange(offset);
final String prevSnapshotUrl = "previous snapshot url";
PageList pageList = client.getPageRangesDiff(blobRange, prevSnapshotUrl);
System.out.println("Valid Page Ranges are:");
for (PageRange pageRange : pageList.getPageRange()) {
System.out.printf("Start: %s, End: %s%n", pageRange.getStart(), pageRange.getEnd());
}
Parameters:
Returns:
getManagedDiskPageRangesDiffWithResponse
public Response
This API only works for managed disk accounts.
Gets the collection of page ranges that differ between a specified snapshot and this page blob. For more information, see the Azure Docs.
Code Samples
BlobRange blobRange = new BlobRange(offset);
final String prevSnapshotUrl = "previous snapshot url";
BlobRequestConditions blobRequestConditions = new BlobRequestConditions().setLeaseId(leaseId);
Context context = new Context(key, value);
PageList pageList = client
.getPageRangesDiffWithResponse(blobRange, prevSnapshotUrl, blobRequestConditions, timeout, context).getValue();
System.out.println("Valid Page Ranges are:");
for (PageRange pageRange : pageList.getPageRange()) {
System.out.printf("Start: %s, End: %s%n", pageRange.getStart(), pageRange.getEnd());
}
Parameters:
Returns:
getPageRanges
@Deprecated
public PageList getPageRanges(BlobRange blobRange)
Deprecated
Returns the list of valid page ranges for a page blob or snapshot of a page blob. For more information, see the Azure Docs.
Code Samples
BlobRange blobRange = new BlobRange(offset);
PageList pageList = client.getPageRanges(blobRange);
System.out.println("Valid Page Ranges are:");
for (PageRange pageRange : pageList.getPageRange()) {
System.out.printf("Start: %s, End: %s%n", pageRange.getStart(), pageRange.getEnd());
}
Parameters:
Returns:
getPageRangesDiff
@Deprecated
public PageList getPageRangesDiff(BlobRange blobRange, String prevSnapshot)
Deprecated
Gets the collection of page ranges that differ between a specified snapshot and this page blob. For more information, see the Azure Docs.
Code Samples
BlobRange blobRange = new BlobRange(offset);
final String prevSnapshot = "previous snapshot";
PageList pageList = client.getPageRangesDiff(blobRange, prevSnapshot);
System.out.println("Valid Page Ranges are:");
for (PageRange pageRange : pageList.getPageRange()) {
System.out.printf("Start: %s, End: %s%n", pageRange.getStart(), pageRange.getEnd());
}
Parameters:
Returns:
getPageRangesDiffWithResponse
@Deprecated
public Response
Deprecated
This API only works for managed disk accounts.
Gets the collection of page ranges that differ between a specified snapshot and this page blob. For more information, see the Azure Docs.
Code Samples
BlobRange blobRange = new BlobRange(offset);
final String prevSnapshot = "previous snapshot";
BlobRequestConditions blobRequestConditions = new BlobRequestConditions().setLeaseId(leaseId);
Context context = new Context(key, value);
PageList pageList = client
.getPageRangesDiffWithResponse(blobRange, prevSnapshot, blobRequestConditions, timeout, context).getValue();
System.out.println("Valid Page Ranges are:");
for (PageRange pageRange : pageList.getPageRange()) {
System.out.printf("Start: %s, End: %s%n", pageRange.getStart(), pageRange.getEnd());
}
Parameters:
Returns:
getPageRangesWithResponse
@Deprecated
public Response
Deprecated
Returns the list of valid page ranges for a page blob or snapshot of a page blob. For more information, see the Azure Docs.
Code Samples
BlobRange blobRange = new BlobRange(offset);
BlobRequestConditions blobRequestConditions = new BlobRequestConditions().setLeaseId(leaseId);
Context context = new Context(key, value);
PageList pageList = client
.getPageRangesWithResponse(blobRange, blobRequestConditions, timeout, context).getValue();
System.out.println("Valid Page Ranges are:");
for (PageRange pageRange : pageList.getPageRange()) {
System.out.printf("Start: %s, End: %s%n", pageRange.getStart(), pageRange.getEnd());
}
Parameters:
Returns:
listPageRanges
public PagedIterable
Returns the list of valid page ranges for a page blob or snapshot of a page blob. For more information, see the Azure Docs.
Code Samples
BlobRange blobRange = new BlobRange(offset);
String prevSnapshot = "previous snapshot";
PagedIterable<PageRangeItem> iterable = client.listPageRanges(blobRange);
for (PageRangeItem item : iterable) {
System.out.printf("Offset: %s, Length: %s, isClear: %s%n", item.getRange().getOffset(),
item.getRange().getLength(), item.isClear());
}
Parameters:
Returns:
listPageRanges
public PagedIterable
Returns the list of valid page ranges for a page blob or snapshot of a page blob. For more information, see the Azure Docs.
Code Samples
ListPageRangesOptions options = new ListPageRangesOptions(new BlobRange(offset))
.setRequestConditions(new BlobRequestConditions().setLeaseId(leaseId))
.setMaxResultsPerPage(1000);
Context context = new Context(key, value);
PagedIterable<PageRangeItem> iter = client
.listPageRanges(options, timeout, context);
System.out.println("Valid Page Ranges are:");
for (PageRangeItem item : iter) {
System.out.printf("Offset: %s, Length: %s, isClear: %s%n", item.getRange().getOffset(),
item.getRange().getLength(), item.isClear());
}
Parameters:
Returns:
listPageRangesDiff
public PagedIterable
Gets the collection of page ranges that differ between a specified snapshot and this page blob. For more information, see the Azure Docs.
Code Samples
BlobRange blobRange = new BlobRange(offset);
String prevSnapshot = "previous snapshot";
PagedIterable<PageRangeItem> iterable = client.listPageRangesDiff(blobRange, prevSnapshot);
for (PageRangeItem item : iterable) {
System.out.printf("Offset: %s, Length: %s, isClear: %s%n", item.getRange().getOffset(),
item.getRange().getLength(), item.isClear());
}
Parameters:
Returns:
listPageRangesDiff
public PagedIterable
Gets the collection of page ranges that differ between a specified snapshot and this page blob. For more information, see the Azure Docs.
Code Samples
ListPageRangesDiffOptions options = new ListPageRangesDiffOptions(new BlobRange(offset), "previous snapshot")
.setRequestConditions(new BlobRequestConditions().setLeaseId(leaseId))
.setMaxResultsPerPage(1000);
Context context = new Context(key, value);
PagedIterable<PageRangeItem> iter = client
.listPageRangesDiff(options, timeout, context);
System.out.println("Valid Page Ranges are:");
for (PageRangeItem item : iter) {
System.out.printf("Offset: %s, Length: %s, isClear: %s%n", item.getRange().getOffset(),
item.getRange().getLength(), item.isClear());
}
Parameters:
Returns:
resize
public PageBlobItem resize(long size)
Resizes the page blob to the specified size (which must be a multiple of 512). For more information, see the Azure Docs.
Code Samples
PageBlobItem pageBlob = client.resize(size);
System.out.printf("Page blob resized with sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
resizeWithResponse
public Response
Resizes the page blob to the specified size (which must be a multiple of 512). For more information, see the Azure Docs.
Code Samples
BlobRequestConditions blobRequestConditions = new BlobRequestConditions().setLeaseId(leaseId);
Context context = new Context(key, value);
PageBlobItem pageBlob = client
.resizeWithResponse(size, blobRequestConditions, timeout, context).getValue();
System.out.printf("Page blob resized with sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
updateSequenceNumber
public PageBlobItem updateSequenceNumber(SequenceNumberActionType action, Long sequenceNumber)
Sets the page blob's sequence number. For more information, see the Azure Docs.
Code Samples
PageBlobItem pageBlob = client.updateSequenceNumber(SequenceNumberActionType.INCREMENT, size);
System.out.printf("Page blob updated to sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
updateSequenceNumberWithResponse
public Response
Sets the page blob's sequence number. For more information, see the Azure Docs.
Code Samples
BlobRequestConditions blobRequestConditions = new BlobRequestConditions().setLeaseId(leaseId);
Context context = new Context(key, value);
PageBlobItem pageBlob = client.updateSequenceNumberWithResponse(
SequenceNumberActionType.INCREMENT, size, blobRequestConditions, timeout, context).getValue();
System.out.printf("Page blob updated to sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
uploadPages
public PageBlobItem uploadPages(PageRange pageRange, InputStream body)
Writes one or more pages to the page blob. The write size must be a multiple of 512. For more information, see the Azure Docs.
Note that the data passed must be replayable if retries are enabled (the default). In other words, the Flux
must produce the same data each time it is subscribed to.
Code Samples
PageRange pageRange = new PageRange()
.setStart(0)
.setEnd(511);
InputStream dataStream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
PageBlobItem pageBlob = client.uploadPages(pageRange, dataStream);
System.out.printf("Uploaded page blob with sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
uploadPagesFromUrl
public PageBlobItem uploadPagesFromUrl(PageRange range, String sourceUrl, Long sourceOffset)
Writes one or more pages from the source page blob to this page blob. The write size must be a multiple of 512. For more information, see the Azure Docs.
Code Samples
PageRange pageRange = new PageRange()
.setStart(0)
.setEnd(511);
PageBlobItem pageBlob = client.uploadPagesFromUrl(pageRange, url, sourceOffset);
System.out.printf("Uploaded page blob from URL with sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
uploadPagesFromUrlWithResponse
public Response
Writes one or more pages from the source page blob to this page blob. The write size must be a multiple of 512. For more information, see the Azure Docs.
Code Samples
PageRange pageRange = new PageRange()
.setStart(0)
.setEnd(511);
InputStream dataStream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
byte[] sourceContentMD5 = new byte[512];
PageBlobRequestConditions pageBlobRequestConditions = new PageBlobRequestConditions().setLeaseId(leaseId);
BlobRequestConditions sourceRequestConditions = new BlobRequestConditions()
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
Context context = new Context(key, value);
PageBlobItem pageBlob = client
.uploadPagesFromUrlWithResponse(pageRange, url, sourceOffset, sourceContentMD5, pageBlobRequestConditions,
sourceRequestConditions, timeout, context).getValue();
System.out.printf("Uploaded page blob from URL with sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
uploadPagesFromUrlWithResponse
public Response
Writes one or more pages from the source page blob to this page blob. The write size must be a multiple of 512. For more information, see the Azure Docs.
Code Samples
PageRange pageRange = new PageRange()
.setStart(0)
.setEnd(511);
InputStream dataStream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
byte[] sourceContentMD5 = new byte[512];
PageBlobRequestConditions pageBlobRequestConditions = new PageBlobRequestConditions().setLeaseId(leaseId);
BlobRequestConditions sourceRequestConditions = new BlobRequestConditions()
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
Context context = new Context(key, value);
PageBlobItem pageBlob = client
.uploadPagesFromUrlWithResponse(new PageBlobUploadPagesFromUrlOptions(pageRange, url)
.setSourceOffset(sourceOffset).setSourceContentMd5(sourceContentMD5)
.setDestinationRequestConditions(pageBlobRequestConditions)
.setSourceRequestConditions(sourceRequestConditions), timeout, context).getValue();
System.out.printf("Uploaded page blob from URL with sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns:
uploadPagesWithResponse
public Response
Writes one or more pages to the page blob. The write size must be a multiple of 512. For more information, see the Azure Docs.
Note that the data passed must be replayable if retries are enabled (the default). In other words, the Flux
must produce the same data each time it is subscribed to.
Code Samples
byte[] md5 = MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8));
PageRange pageRange = new PageRange()
.setStart(0)
.setEnd(511);
InputStream dataStream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
PageBlobRequestConditions pageBlobRequestConditions = new PageBlobRequestConditions().setLeaseId(leaseId);
Context context = new Context(key, value);
PageBlobItem pageBlob = client
.uploadPagesWithResponse(pageRange, dataStream, md5, pageBlobRequestConditions, timeout, context).getValue();
System.out.printf("Uploaded page blob with sequence number %s%n", pageBlob.getBlobSequenceNumber());
Parameters:
Returns: