0
# Model Classes & Enums
1
2
This documentation covers the key model classes, properties, and enums used throughout the Azure Storage Blob Java SDK for representing data, configuration, and service responses.
3
4
## Core Model Classes
5
6
### BlobProperties
7
8
Comprehensive properties and metadata for a blob.
9
10
```java
11
import com.azure.storage.blob.models.BlobProperties;
12
import java.time.OffsetDateTime;
13
import java.util.Map;
14
15
// Get blob properties
16
BlobProperties properties = blobClient.getProperties();
17
18
// Basic blob information
19
System.out.println("Blob size: " + properties.getBlobSize() + " bytes");
20
System.out.println("Blob type: " + properties.getBlobType()); // BLOCK_BLOB, APPEND_BLOB, PAGE_BLOB
21
System.out.println("ETag: " + properties.getETag());
22
System.out.println("Last modified: " + properties.getLastModified());
23
System.out.println("Creation time: " + properties.getCreationTime());
24
25
// Content properties
26
System.out.println("Content type: " + properties.getContentType());
27
System.out.println("Content encoding: " + properties.getContentEncoding());
28
System.out.println("Content language: " + properties.getContentLanguage());
29
System.out.println("Content disposition: " + properties.getContentDisposition());
30
System.out.println("Cache control: " + properties.getCacheControl());
31
System.out.println("Content MD5: " + Arrays.toString(properties.getContentMd5()));
32
33
// Access tier and archival
34
System.out.println("Access tier: " + properties.getAccessTier());
35
System.out.println("Tier inferred: " + properties.getAccessTierInferred());
36
System.out.println("Tier change time: " + properties.getAccessTierChangeTime());
37
System.out.println("Archive status: " + properties.getArchiveStatus());
38
39
// Versioning and snapshots
40
System.out.println("Version ID: " + properties.getVersionId());
41
System.out.println("Is current version: " + properties.isCurrentVersion());
42
System.out.println("Deleted time: " + properties.getDeletedTime());
43
System.out.println("Remaining retention days: " + properties.getRemainingRetentionDays());
44
45
// Lease information
46
System.out.println("Lease status: " + properties.getLeaseStatus());
47
System.out.println("Lease state: " + properties.getLeaseState());
48
System.out.println("Lease duration: " + properties.getLeaseDuration());
49
50
// Copy information
51
System.out.println("Copy ID: " + properties.getCopyId());
52
System.out.println("Copy status: " + properties.getCopyStatus());
53
System.out.println("Copy source: " + properties.getCopySource());
54
System.out.println("Copy progress: " + properties.getCopyProgress());
55
System.out.println("Copy completion time: " + properties.getCopyCompletionTime());
56
57
// Encryption and security
58
System.out.println("Server encrypted: " + properties.isServerEncrypted());
59
System.out.println("Encryption key SHA256: " + properties.getEncryptionKeySha256());
60
System.out.println("Encryption scope: " + properties.getEncryptionScope());
61
62
// Compliance and governance
63
System.out.println("Has legal hold: " + properties.hasLegalHold());
64
BlobImmutabilityPolicy immutabilityPolicy = properties.getImmutabilityPolicy();
65
if (immutabilityPolicy != null) {
66
System.out.println("Immutability expiry: " + immutabilityPolicy.getExpiryTime());
67
System.out.println("Immutability mode: " + immutabilityPolicy.getPolicyMode());
68
}
69
70
// Metadata and tags
71
Map<String, String> metadata = properties.getMetadata();
72
System.out.println("Metadata count: " + metadata.size());
73
System.out.println("Tag count: " + properties.getTagCount());
74
75
// Page blob specific
76
if (properties.getBlobType() == BlobType.PAGE_BLOB) {
77
System.out.println("Blob sequence number: " + properties.getBlobSequenceNumber());
78
}
79
80
// Block blob specific
81
if (properties.getBlobType() == BlobType.BLOCK_BLOB) {
82
System.out.println("Committed block count: " + properties.getCommittedBlockCount());
83
}
84
85
// Object replication
86
List<ObjectReplicationPolicy> replicationPolicies = properties.getObjectReplicationSourcePolicies();
87
if (replicationPolicies != null) {
88
System.out.println("Object replication policies: " + replicationPolicies.size());
89
}
90
System.out.println("Replication destination policy: " + properties.getObjectReplicationDestinationPolicyId());
91
```
92
93
### BlobContainerProperties
94
95
Properties and metadata for a blob container.
96
97
```java
98
import com.azure.storage.blob.models.BlobContainerProperties;
99
100
// Get container properties
101
BlobContainerProperties containerProps = containerClient.getProperties();
102
103
// Basic container information
104
System.out.println("ETag: " + containerProps.getETag());
105
System.out.println("Last modified: " + containerProps.getLastModified());
106
System.out.println("Public access: " + containerProps.getPublicAccess());
107
108
// Lease information
109
System.out.println("Lease status: " + containerProps.getLeaseStatus());
110
System.out.println("Lease state: " + containerProps.getLeaseState());
111
System.out.println("Lease duration: " + containerProps.getLeaseDuration());
112
113
// Security and compliance
114
System.out.println("Has immutability policy: " + containerProps.hasImmutabilityPolicy());
115
System.out.println("Has legal hold: " + containerProps.hasLegalHold());
116
117
// Encryption
118
System.out.println("Default encryption scope: " + containerProps.getDefaultEncryptionScope());
119
System.out.println("Encryption scope override prevented: " +
120
containerProps.isEncryptionScopeOverridePrevented());
121
122
// Metadata
123
Map<String, String> containerMetadata = containerProps.getMetadata();
124
System.out.println("Container metadata:");
125
containerMetadata.forEach((key, value) ->
126
System.out.println(" " + key + ": " + value));
127
```
128
129
### BlobItem
130
131
Represents a blob item in listing operations.
132
133
```java
134
import com.azure.storage.blob.models.BlobItem;
135
import com.azure.storage.blob.models.BlobItemProperties;
136
137
// List blobs and examine blob items
138
PagedIterable<BlobItem> blobs = containerClient.listBlobs();
139
for (BlobItem blobItem : blobs) {
140
// Basic blob item information
141
System.out.println("Blob name: " + blobItem.getName());
142
System.out.println("Is deleted: " + blobItem.isDeleted());
143
System.out.println("Snapshot: " + blobItem.getSnapshot());
144
System.out.println("Version ID: " + blobItem.getVersionId());
145
System.out.println("Is current version: " + blobItem.isCurrentVersion());
146
System.out.println("Has versions only: " + blobItem.hasVersionsOnly());
147
148
// Blob properties from listing
149
BlobItemProperties itemProps = blobItem.getProperties();
150
System.out.println("Size: " + itemProps.getContentLength() + " bytes");
151
System.out.println("Content type: " + itemProps.getContentType());
152
System.out.println("Last modified: " + itemProps.getLastModified());
153
System.out.println("ETag: " + itemProps.getETag());
154
System.out.println("Blob type: " + itemProps.getBlobType());
155
System.out.println("Access tier: " + itemProps.getAccessTier());
156
System.out.println("Server encrypted: " + itemProps.isServerEncrypted());
157
158
// Metadata and tags (if requested in list options)
159
Map<String, String> itemMetadata = blobItem.getMetadata();
160
if (itemMetadata != null) {
161
System.out.println("Metadata entries: " + itemMetadata.size());
162
}
163
164
Map<String, String> itemTags = blobItem.getTags();
165
if (itemTags != null) {
166
System.out.println("Tag entries: " + itemTags.size());
167
}
168
169
// Object replication
170
List<ObjectReplicationPolicy> replicationPolicies = blobItem.getObjectReplicationSourcePolicies();
171
if (replicationPolicies != null) {
172
System.out.println("Replication policies: " + replicationPolicies.size());
173
}
174
}
175
```
176
177
### BlobServiceProperties
178
179
Service-level properties for Azure Blob Storage account.
180
181
```java
182
import com.azure.storage.blob.models.*;
183
184
// Get and configure service properties
185
BlobServiceProperties serviceProps = serviceClient.getProperties();
186
187
// Logging configuration
188
BlobAnalyticsLogging logging = serviceProps.getLogging();
189
if (logging != null) {
190
System.out.println("Logging version: " + logging.getVersion());
191
System.out.println("Delete enabled: " + logging.isDeleteEnabled());
192
System.out.println("Read enabled: " + logging.isReadEnabled());
193
System.out.println("Write enabled: " + logging.isWriteEnabled());
194
195
BlobRetentionPolicy logRetention = logging.getRetentionPolicy();
196
if (logRetention != null) {
197
System.out.println("Log retention enabled: " + logRetention.isEnabled());
198
System.out.println("Log retention days: " + logRetention.getDays());
199
}
200
}
201
202
// Metrics configuration
203
BlobMetrics hourMetrics = serviceProps.getHourMetrics();
204
if (hourMetrics != null) {
205
System.out.println("Hour metrics enabled: " + hourMetrics.isEnabled());
206
System.out.println("Include APIs: " + hourMetrics.isIncludeApis());
207
208
BlobRetentionPolicy metricsRetention = hourMetrics.getRetentionPolicy();
209
if (metricsRetention != null) {
210
System.out.println("Metrics retention days: " + metricsRetention.getDays());
211
}
212
}
213
214
BlobMetrics minuteMetrics = serviceProps.getMinuteMetrics();
215
if (minuteMetrics != null) {
216
System.out.println("Minute metrics enabled: " + minuteMetrics.isEnabled());
217
}
218
219
// CORS rules
220
List<BlobCorsRule> corsRules = serviceProps.getCors();
221
if (corsRules != null) {
222
System.out.println("CORS rules count: " + corsRules.size());
223
for (BlobCorsRule corsRule : corsRules) {
224
System.out.println("Allowed origins: " + corsRule.getAllowedOrigins());
225
System.out.println("Allowed methods: " + corsRule.getAllowedMethods());
226
System.out.println("Max age: " + corsRule.getMaxAgeInSeconds());
227
}
228
}
229
230
// Default service version
231
System.out.println("Default service version: " + serviceProps.getDefaultServiceVersion());
232
233
// Delete retention policy
234
BlobRetentionPolicy deleteRetention = serviceProps.getDeleteRetentionPolicy();
235
if (deleteRetention != null) {
236
System.out.println("Delete retention enabled: " + deleteRetention.isEnabled());
237
System.out.println("Delete retention days: " + deleteRetention.getDays());
238
}
239
240
// Static website configuration
241
BlobStaticWebsite staticWebsite = serviceProps.getStaticWebsite();
242
if (staticWebsite != null) {
243
System.out.println("Static website enabled: " + staticWebsite.isEnabled());
244
System.out.println("Index document: " + staticWebsite.getIndexDocument());
245
System.out.println("Error document: " + staticWebsite.getErrorDocument404Path());
246
}
247
```
248
249
## HTTP Headers and Request Models
250
251
### BlobHttpHeaders
252
253
HTTP headers for blob content.
254
255
```java
256
import com.azure.storage.blob.models.BlobHttpHeaders;
257
258
// Create and configure HTTP headers
259
BlobHttpHeaders headers = new BlobHttpHeaders()
260
.setContentType("application/pdf")
261
.setContentLanguage("en-US")
262
.setContentEncoding("gzip")
263
.setCacheControl("public, max-age=31536000")
264
.setContentDisposition("attachment; filename=document.pdf");
265
266
// Calculate and set content MD5
267
byte[] content = Files.readAllBytes(Paths.get("document.pdf"));
268
MessageDigest md5 = MessageDigest.getInstance("MD5");
269
byte[] contentMd5 = md5.digest(content);
270
headers.setContentMd5(contentMd5);
271
272
// Use headers in upload
273
blobClient.upload(BinaryData.fromBytes(content), true);
274
blobClient.setHttpHeaders(headers);
275
276
// Get current headers
277
BlobProperties properties = blobClient.getProperties();
278
System.out.println("Content type: " + properties.getContentType());
279
System.out.println("Content encoding: " + properties.getContentEncoding());
280
System.out.println("Content language: " + properties.getContentLanguage());
281
System.out.println("Content disposition: " + properties.getContentDisposition());
282
System.out.println("Cache control: " + properties.getCacheControl());
283
System.out.println("Content MD5: " + Arrays.toString(properties.getContentMd5()));
284
```
285
286
### BlobRequestConditions
287
288
Conditional request parameters for blob operations.
289
290
```java
291
import com.azure.storage.blob.models.BlobRequestConditions;
292
import java.time.OffsetDateTime;
293
294
// Create request conditions for optimistic concurrency control
295
BlobRequestConditions conditions = new BlobRequestConditions()
296
.setIfMatch("\"0x8D64EA4B2C6B7A0\"") // Only if ETag matches
297
.setIfNoneMatch("*") // Only if blob doesn't exist
298
.setIfModifiedSince(OffsetDateTime.now().minusHours(1)) // Only if modified since
299
.setIfUnmodifiedSince(OffsetDateTime.now()) // Only if not modified since
300
.setLeaseId("lease-id-12345") // Only with valid lease
301
.setTagsConditions("\"environment\" = 'production' AND \"team\" = 'backend'"); // Tag-based conditions
302
303
// Use conditions in operations
304
try {
305
blobClient.uploadWithResponse(
306
new BlobParallelUploadOptions(BinaryData.fromString("Updated content"))
307
.setRequestConditions(conditions),
308
Duration.ofMinutes(5),
309
Context.NONE
310
);
311
System.out.println("Upload succeeded with conditions");
312
} catch (BlobStorageException ex) {
313
if (ex.getStatusCode() == 412) { // Precondition Failed
314
System.err.println("Conditional operation failed: " + ex.getErrorCode());
315
} else {
316
throw ex;
317
}
318
}
319
320
// Specialized conditions for different blob types
321
AppendBlobRequestConditions appendConditions = new AppendBlobRequestConditions()
322
.setIfMatch(currentETag)
323
.setAppendPositionEqual(expectedOffset) // Append only at specific position
324
.setMaxSize(100 * 1024 * 1024L); // Ensure blob doesn't exceed 100MB
325
326
PageBlobRequestConditions pageConditions = new PageBlobRequestConditions()
327
.setIfMatch(currentETag)
328
.setIfSequenceNumberEqual(expectedSequenceNumber) // Page blob sequence number check
329
.setIfSequenceNumberLessThan(maxSequenceNumber)
330
.setIfSequenceNumberLessThanOrEqual(limitSequenceNumber);
331
```
332
333
## Response and Result Models
334
335
### BlockBlobItem, AppendBlobItem, PageBlobItem
336
337
Results from specialized blob operations.
338
339
```java
340
import com.azure.storage.blob.models.*;
341
342
// Block blob operation results
343
BlockBlobItem blockResult = blockBlobClient.upload(BinaryData.fromString("Block content"), true);
344
System.out.println("Block blob ETag: " + blockResult.getETag());
345
System.out.println("Last modified: " + blockResult.getLastModified());
346
System.out.println("Content MD5: " + Arrays.toString(blockResult.getContentMd5()));
347
System.out.println("Version ID: " + blockResult.getVersionId());
348
System.out.println("Server encrypted: " + blockResult.isServerEncrypted());
349
System.out.println("Encryption key SHA256: " + blockResult.getEncryptionKeySha256());
350
351
// Append blob operation results
352
appendBlobClient.create();
353
AppendBlobItem appendResult = appendBlobClient.appendBlock(BinaryData.fromString("Log entry"));
354
System.out.println("Append ETag: " + appendResult.getETag());
355
System.out.println("Last modified: " + appendResult.getLastModified());
356
System.out.println("Append offset: " + appendResult.getBlobAppendOffset());
357
System.out.println("Committed block count: " + appendResult.getBlobCommittedBlockCount());
358
359
// Page blob operation results
360
pageBlobClient.create(1024 * 512); // 512KB
361
PageBlobItem pageResult = pageBlobClient.uploadPages(
362
new PageRange().setStart(0).setEnd(511),
363
BinaryData.fromBytes(new byte[512])
364
);
365
System.out.println("Page blob ETag: " + pageResult.getETag());
366
System.out.println("Last modified: " + pageResult.getLastModified());
367
System.out.println("Blob sequence number: " + pageResult.getBlobSequenceNumber());
368
```
369
370
### BlobCopyInfo and Copy Status
371
372
Information about blob copy operations.
373
374
```java
375
// Start copy operation
376
String sourceUrl = "https://source.blob.core.windows.net/container/source.txt";
377
SyncPoller<BlobCopyInfo, Void> copyPoller = blobClient.beginCopy(sourceUrl, Duration.ofMinutes(1));
378
379
// Monitor copy progress
380
while (!copyPoller.poll().getStatus().isComplete()) {
381
BlobCopyInfo copyInfo = copyPoller.poll().getValue();
382
383
System.out.println("Copy ID: " + copyInfo.getCopyId());
384
System.out.println("Copy status: " + copyInfo.getCopyStatus());
385
System.out.println("Copy source: " + copyInfo.getCopySource());
386
387
if (copyInfo.getTotalBytes() != null && copyInfo.getBytesTransferred() != null) {
388
long progress = (copyInfo.getBytesTransferred() * 100) / copyInfo.getTotalBytes();
389
System.out.println("Progress: " + progress + "% (" +
390
copyInfo.getBytesTransferred() + "/" + copyInfo.getTotalBytes() + " bytes)");
391
}
392
393
if (copyInfo.getCopyStatus() == CopyStatusType.FAILED) {
394
System.err.println("Copy failed: " + copyInfo.getError());
395
break;
396
}
397
398
Thread.sleep(1000); // Wait 1 second
399
}
400
401
// Get final copy status
402
BlobProperties finalProperties = blobClient.getProperties();
403
System.out.println("Final copy status: " + finalProperties.getCopyStatus());
404
System.out.println("Copy completion time: " + finalProperties.getCopyCompletionTime());
405
```
406
407
## Storage Account and Service Models
408
409
### StorageAccountInfo
410
411
Information about the storage account.
412
413
```java
414
import com.azure.storage.blob.models.StorageAccountInfo;
415
416
// Get account information
417
StorageAccountInfo accountInfo = serviceClient.getAccountInfo();
418
419
System.out.println("SKU name: " + accountInfo.getSkuName());
420
System.out.println("Account kind: " + accountInfo.getAccountKind());
421
System.out.println("Hierarchical namespace enabled: " + accountInfo.isHierarchicalNamespaceEnabled());
422
423
// Account kind values
424
AccountKind kind = accountInfo.getAccountKind();
425
switch (kind) {
426
case STORAGE:
427
System.out.println("General-purpose v1 account");
428
break;
429
case STORAGE_V2:
430
System.out.println("General-purpose v2 account");
431
break;
432
case BLOB_STORAGE:
433
System.out.println("Blob storage account");
434
break;
435
case BLOCK_BLOB_STORAGE:
436
System.out.println("Premium block blob storage account");
437
break;
438
default:
439
System.out.println("Other account type: " + kind);
440
}
441
442
// SKU name values indicate performance tier
443
SkuName sku = accountInfo.getSkuName();
444
System.out.println("Performance tier: " + (sku.toString().contains("Premium") ? "Premium" : "Standard"));
445
```
446
447
### BlobServiceStatistics
448
449
Statistics for blob service geo-replication.
450
451
```java
452
import com.azure.storage.blob.models.BlobServiceStatistics;
453
import com.azure.storage.blob.models.GeoReplication;
454
455
// Get service statistics (only available for RA-GRS accounts)
456
try {
457
BlobServiceStatistics stats = serviceClient.getStatistics();
458
459
GeoReplication geoReplication = stats.getGeoReplication();
460
if (geoReplication != null) {
461
System.out.println("Geo-replication status: " + geoReplication.getStatus());
462
System.out.println("Last sync time: " + geoReplication.getLastSyncTime());
463
464
switch (geoReplication.getStatus()) {
465
case LIVE:
466
System.out.println("Secondary region is available for read access");
467
break;
468
case BOOTSTRAP:
469
System.out.println("Initial synchronization is in progress");
470
break;
471
case UNAVAILABLE:
472
System.out.println("Secondary region is unavailable");
473
break;
474
default:
475
System.out.println("Unknown replication status: " + geoReplication.getStatus());
476
}
477
} else {
478
System.out.println("Geo-replication not configured");
479
}
480
} catch (BlobStorageException ex) {
481
if (ex.getStatusCode() == 400) {
482
System.out.println("Statistics not available (account not configured for geo-replication)");
483
} else {
484
throw ex;
485
}
486
}
487
```
488
489
### TaggedBlobItem
490
491
Represents a blob found by tag-based queries.
492
493
```java
494
import com.azure.storage.blob.models.TaggedBlobItem;
495
496
// Find blobs by tags
497
String tagQuery = "environment='production' AND team='backend'";
498
PagedIterable<TaggedBlobItem> taggedBlobs = serviceClient.findBlobsByTags(tagQuery);
499
500
for (TaggedBlobItem taggedBlob : taggedBlobs) {
501
System.out.println("Blob name: " + taggedBlob.getName());
502
System.out.println("Container: " + taggedBlob.getContainerName());
503
504
// Access tags
505
BlobTags tags = taggedBlob.getTags();
506
Map<String, String> tagMap = tags.toMap();
507
System.out.println("Tags:");
508
tagMap.forEach((key, value) -> System.out.println(" " + key + ": " + value));
509
}
510
```
511
512
## Enums and Constants
513
514
### BlobType
515
516
Types of blobs supported by Azure Storage.
517
518
```java
519
import com.azure.storage.blob.models.BlobType;
520
521
// Check blob type from properties
522
BlobProperties properties = blobClient.getProperties();
523
BlobType blobType = properties.getBlobType();
524
525
switch (blobType) {
526
case BLOCK_BLOB:
527
System.out.println("Block blob - optimized for streaming and general-purpose scenarios");
528
BlockBlobClient blockClient = blobClient.getBlockBlobClient();
529
break;
530
531
case APPEND_BLOB:
532
System.out.println("Append blob - optimized for append operations and logging");
533
AppendBlobClient appendClient = blobClient.getAppendBlobClient();
534
break;
535
536
case PAGE_BLOB:
537
System.out.println("Page blob - optimized for random read/write operations");
538
PageBlobClient pageClient = blobClient.getPageBlobClient();
539
break;
540
541
default:
542
System.out.println("Unknown blob type: " + blobType);
543
}
544
```
545
546
### AccessTier
547
548
Storage access tiers for cost optimization.
549
550
```java
551
import com.azure.storage.blob.models.AccessTier;
552
553
// Set appropriate access tier based on access patterns
554
AccessTier tier = determineOptimalTier(blobAccessFrequency);
555
blobClient.setAccessTier(tier);
556
557
// Access tier values and their characteristics
558
public AccessTier determineOptimalTier(String accessFrequency) {
559
switch (accessFrequency.toLowerCase()) {
560
case "frequent":
561
return AccessTier.HOT; // Highest storage cost, lowest access cost
562
case "infrequent":
563
return AccessTier.COOL; // Lower storage cost, higher access cost (30+ days)
564
case "rarely":
565
return AccessTier.COLD; // Even lower storage cost (90+ days)
566
case "archive":
567
return AccessTier.ARCHIVE; // Lowest storage cost, highest access cost (180+ days)
568
default:
569
return AccessTier.HOT;
570
}
571
}
572
573
// Premium access tiers for premium storage accounts
574
if (accountInfo.getSkuName().toString().contains("Premium")) {
575
// Premium tiers: P4, P6, P10, P15, P20, P30, P40, P50, P60, P70, P80
576
blobClient.setAccessTier(AccessTier.P30); // Premium performance tier
577
}
578
579
// Check current access tier
580
BlobProperties properties = blobClient.getProperties();
581
System.out.println("Current access tier: " + properties.getAccessTier());
582
System.out.println("Tier inferred: " + properties.getAccessTierInferred());
583
System.out.println("Tier change time: " + properties.getAccessTierChangeTime());
584
585
// Archive status for blobs being rehydrated
586
ArchiveStatus archiveStatus = properties.getArchiveStatus();
587
if (archiveStatus != null) {
588
System.out.println("Archive status: " + archiveStatus);
589
switch (archiveStatus) {
590
case REHYDRATE_PENDING_TO_HOT:
591
System.out.println("Blob is being rehydrated to Hot tier");
592
break;
593
case REHYDRATE_PENDING_TO_COOL:
594
System.out.println("Blob is being rehydrated to Cool tier");
595
break;
596
case REHYDRATE_PENDING_TO_COLD:
597
System.out.println("Blob is being rehydrated to Cold tier");
598
break;
599
}
600
}
601
```
602
603
### PublicAccessType
604
605
Public access levels for blob containers.
606
607
```java
608
import com.azure.storage.blob.models.PublicAccessType;
609
610
// Configure container public access
611
PublicAccessType publicAccess = PublicAccessType.BLOB;
612
containerClient.setAccessPolicy(publicAccess, null);
613
614
// Public access types
615
switch (publicAccess) {
616
case CONTAINER:
617
System.out.println("Container and blobs can be read by anonymous clients");
618
// Anonymous clients can:
619
// - List blobs in the container
620
// - Read container metadata and properties
621
// - Read blob data and metadata
622
break;
623
624
case BLOB:
625
System.out.println("Only blobs can be read by anonymous clients");
626
// Anonymous clients can:
627
// - Read blob data and metadata (with direct URL)
628
// Cannot list blobs or read container properties
629
break;
630
631
case null:
632
System.out.println("No public access - authentication required");
633
// All access requires authentication
634
break;
635
}
636
637
// Check current public access level
638
BlobContainerProperties containerProps = containerClient.getProperties();
639
PublicAccessType currentAccess = containerProps.getPublicAccess();
640
System.out.println("Current public access: " +
641
(currentAccess != null ? currentAccess : "None"));
642
```
643
644
### Lease States and Status
645
646
Lease information for concurrency control.
647
648
```java
649
import com.azure.storage.blob.models.*;
650
651
// Check lease status from properties
652
BlobProperties properties = blobClient.getProperties();
653
654
LeaseStatusType leaseStatus = properties.getLeaseStatus();
655
LeaseStateType leaseState = properties.getLeaseState();
656
LeaseDurationType leaseDuration = properties.getLeaseDuration();
657
658
System.out.println("Lease status: " + leaseStatus);
659
System.out.println("Lease state: " + leaseState);
660
System.out.println("Lease duration: " + leaseDuration);
661
662
// Lease status interpretation
663
switch (leaseStatus) {
664
case LOCKED:
665
System.out.println("Blob has an active lease");
666
break;
667
case UNLOCKED:
668
System.out.println("Blob is not leased");
669
break;
670
}
671
672
// Lease state details
673
switch (leaseState) {
674
case AVAILABLE:
675
System.out.println("Blob is available for leasing");
676
break;
677
case LEASED:
678
System.out.println("Blob is currently leased");
679
break;
680
case EXPIRED:
681
System.out.println("Lease has expired but not yet broken");
682
break;
683
case BREAKING:
684
System.out.println("Lease is being broken");
685
break;
686
case BROKEN:
687
System.out.println("Lease has been broken");
688
break;
689
}
690
691
// Lease duration types
692
if (leaseDuration != null) {
693
switch (leaseDuration) {
694
case INFINITE:
695
System.out.println("Infinite lease duration");
696
break;
697
case FIXED:
698
System.out.println("Fixed lease duration");
699
break;
700
}
701
}
702
```
703
704
### Copy Status and Operations
705
706
Copy operation status and information.
707
708
```java
709
import com.azure.storage.blob.models.CopyStatusType;
710
711
// Monitor copy operation status
712
BlobProperties properties = blobClient.getProperties();
713
CopyStatusType copyStatus = properties.getCopyStatus();
714
715
if (copyStatus != null) {
716
switch (copyStatus) {
717
case PENDING:
718
System.out.println("Copy operation is in progress");
719
System.out.println("Progress: " + properties.getCopyProgress());
720
break;
721
722
case SUCCESS:
723
System.out.println("Copy operation completed successfully");
724
System.out.println("Copy completion time: " + properties.getCopyCompletionTime());
725
break;
726
727
case ABORTED:
728
System.out.println("Copy operation was aborted");
729
System.out.println("Copy status description: " + properties.getCopyStatusDescription());
730
break;
731
732
case FAILED:
733
System.out.println("Copy operation failed");
734
System.out.println("Copy status description: " + properties.getCopyStatusDescription());
735
break;
736
}
737
738
System.out.println("Copy ID: " + properties.getCopyId());
739
System.out.println("Copy source: " + properties.getCopySource());
740
}
741
```
742
743
### Service Version
744
745
Azure Storage service API versions.
746
747
```java
748
import com.azure.storage.blob.BlobServiceVersion;
749
750
// Use latest service version
751
BlobServiceVersion latest = BlobServiceVersion.getLatest();
752
System.out.println("Latest service version: " + latest.getVersion());
753
754
// Create client with specific service version
755
BlobServiceClient serviceClient = new BlobServiceClientBuilder()
756
.connectionString(connectionString)
757
.serviceVersion(BlobServiceVersion.V2023_11_03)
758
.buildClient();
759
760
// Available versions (subset of most common ones)
761
BlobServiceVersion[] commonVersions = {
762
BlobServiceVersion.V2023_11_03, // Latest stable
763
BlobServiceVersion.V2023_08_03,
764
BlobServiceVersion.V2023_05_03,
765
BlobServiceVersion.V2023_01_03,
766
BlobServiceVersion.V2022_11_02,
767
BlobServiceVersion.V2021_12_02,
768
BlobServiceVersion.V2021_10_04,
769
BlobServiceVersion.V2021_08_06
770
};
771
772
for (BlobServiceVersion version : commonVersions) {
773
System.out.println("Available version: " + version.getVersion());
774
}
775
776
// Get current service version from client
777
BlobServiceVersion currentVersion = serviceClient.getServiceVersion();
778
System.out.println("Client service version: " + currentVersion.getVersion());
779
```
780
781
## Error Handling Models
782
783
### BlobStorageException and Error Codes
784
785
```java
786
import com.azure.storage.blob.models.BlobStorageException;
787
import com.azure.storage.blob.models.BlobErrorCode;
788
789
try {
790
blobClient.upload(BinaryData.fromString("content"), false); // Don't overwrite
791
} catch (BlobStorageException ex) {
792
System.err.println("Storage operation failed:");
793
System.err.println("Status code: " + ex.getStatusCode());
794
System.err.println("Error code: " + ex.getErrorCode());
795
System.err.println("Error message: " + ex.getMessage());
796
System.err.println("Request ID: " + ex.getValue().getRequestId());
797
798
// Handle specific error conditions
799
BlobErrorCode errorCode = ex.getErrorCode();
800
switch (errorCode) {
801
case BLOB_ALREADY_EXISTS:
802
System.err.println("Blob exists - use overwrite option or different name");
803
break;
804
case BLOB_NOT_FOUND:
805
System.err.println("Blob not found - check blob name and container");
806
break;
807
case CONTAINER_NOT_FOUND:
808
System.err.println("Container not found - create container first");
809
break;
810
case AUTHENTICATION_FAILED:
811
System.err.println("Authentication failed - check credentials");
812
break;
813
case AUTHORIZATION_FAILURE:
814
System.err.println("Authorization failed - check permissions");
815
break;
816
case REQUEST_BODY_TOO_LARGE:
817
System.err.println("Request too large - use parallel upload for large files");
818
break;
819
case INVALID_BLOB_OR_BLOCK:
820
System.err.println("Invalid blob or block - check content and size");
821
break;
822
case LEASE_ID_MISMATCH:
823
System.err.println("Lease ID mismatch - provide correct lease ID");
824
break;
825
case CONDITION_NOT_MET:
826
System.err.println("Precondition failed - check conditional parameters");
827
break;
828
default:
829
System.err.println("Other error: " + errorCode);
830
}
831
}
832
```
833
834
## Utility and Helper Models
835
836
### BlobRange
837
838
Represents a byte range for partial blob operations.
839
840
```java
841
import com.azure.storage.blob.models.BlobRange;
842
843
// Download specific range of blob
844
BlobRange range = new BlobRange(1024, 4096L); // Bytes 1024-5119 (4096 bytes)
845
BinaryData rangeData = blobClient.downloadContentWithResponse(
846
new BlobDownloadOptions().setRange(range),
847
Duration.ofMinutes(2),
848
Context.NONE
849
).getValue();
850
851
System.out.println("Downloaded " + rangeData.getLength() + " bytes from range");
852
853
// Range for entire blob from offset
854
BlobRange fromOffset = new BlobRange(1024); // From byte 1024 to end
855
BinaryData tailData = blobClient.downloadContentWithResponse(
856
new BlobDownloadOptions().setRange(fromOffset),
857
Duration.ofMinutes(2),
858
Context.NONE
859
).getValue();
860
861
// Use ranges with page blob operations
862
PageRange pageRange = new PageRange().setStart(0).setEnd(511); // First 512-byte page
863
pageBlobClient.uploadPages(pageRange, BinaryData.fromBytes(new byte[512]));
864
865
// Clear specific page range
866
PageRange clearRange = new PageRange().setStart(512).setEnd(1023); // Second page
867
pageBlobClient.clearPages(clearRange);
868
```
869
870
## Related Documentation
871
872
- [← Back to Overview](index.md)
873
- [← Specialized Blob Types](specialized-clients.md)
874
- [Configuration Options →](options.md)
875
- [Security & Authentication →](security.md)
876
- [Streaming & Advanced I/O →](streaming.md)