@@ -150,19 +150,17 @@ public void createContainer(String account, String container) throws URISyntaxEx
150
150
public void deleteFiles (String account , String container , String path ) throws URISyntaxException , StorageException {
151
151
final Tuple <CloudBlobClient , Supplier <OperationContext >> client = client (account );
152
152
// container name must be lower case.
153
- final CloudBlobContainer blobContainer = client .v1 ().getContainerReference (container );
154
153
logger .trace (() -> new ParameterizedMessage ("delete files container [{}], path [{}]" , container , path ));
155
154
SocketAccess .doPrivilegedVoidException (() -> {
156
- if (blobContainer .exists ()) {
157
- // list the blobs using a flat blob listing mode
158
- for (final ListBlobItem blobItem : blobContainer .listBlobs (path , true , EnumSet .noneOf (BlobListingDetails .class ), null ,
159
- client .v2 ().get ())) {
160
- final String blobName = blobNameFromUri (blobItem .getUri ());
161
- logger .trace (() -> new ParameterizedMessage ("removing blob [{}] full URI was [{}]" , blobName , blobItem .getUri ()));
162
- // don't call {@code #deleteBlob}, use the same client
163
- final CloudBlockBlob azureBlob = blobContainer .getBlockBlobReference (blobName );
164
- azureBlob .delete (DeleteSnapshotsOption .NONE , null , null , client .v2 ().get ());
165
- }
155
+ // list the blobs using a flat blob listing mode
156
+ final CloudBlobContainer blobContainer = client .v1 ().getContainerReference (container );
157
+ for (final ListBlobItem blobItem : blobContainer .listBlobs (path , true , EnumSet .noneOf (BlobListingDetails .class ), null ,
158
+ client .v2 ().get ())) {
159
+ final String blobName = blobNameFromUri (blobItem .getUri ());
160
+ logger .trace (() -> new ParameterizedMessage ("removing blob [{}] full URI was [{}]" , blobName , blobItem .getUri ()));
161
+ // don't call {@code #deleteBlob}, use the same client
162
+ final CloudBlockBlob azureBlob = blobContainer .getBlockBlobReference (blobName );
163
+ azureBlob .delete (DeleteSnapshotsOption .NONE , null , null , client .v2 ().get ());
166
164
}
167
165
});
168
166
}
@@ -192,11 +190,8 @@ public boolean blobExists(String account, String container, String blob)
192
190
final Tuple <CloudBlobClient , Supplier <OperationContext >> client = client (account );
193
191
final CloudBlobContainer blobContainer = client .v1 ().getContainerReference (container );
194
192
return SocketAccess .doPrivilegedException (() -> {
195
- if (blobContainer .exists (null , null , client .v2 ().get ())) {
196
- final CloudBlockBlob azureBlob = blobContainer .getBlockBlobReference (blob );
197
- return azureBlob .exists (null , null , client .v2 ().get ());
198
- }
199
- return false ;
193
+ final CloudBlockBlob azureBlob = blobContainer .getBlockBlobReference (blob );
194
+ return azureBlob .exists (null , null , client .v2 ().get ());
200
195
});
201
196
}
202
197
@@ -207,11 +202,9 @@ public void deleteBlob(String account, String container, String blob) throws URI
207
202
final CloudBlobContainer blobContainer = client .v1 ().getContainerReference (container );
208
203
logger .trace (() -> new ParameterizedMessage ("delete blob for container [{}], blob [{}]" , container , blob ));
209
204
SocketAccess .doPrivilegedVoidException (() -> {
210
- if (blobContainer .exists (null , null , client .v2 ().get ())) {
211
- final CloudBlockBlob azureBlob = blobContainer .getBlockBlobReference (blob );
212
- logger .trace (() -> new ParameterizedMessage ("container [{}]: blob [{}] found. removing." , container , blob ));
213
- azureBlob .delete (DeleteSnapshotsOption .NONE , null , null , client .v2 ().get ());
214
- }
205
+ final CloudBlockBlob azureBlob = blobContainer .getBlockBlobReference (blob );
206
+ logger .trace (() -> new ParameterizedMessage ("container [{}]: blob [{}] found. removing." , container , blob ));
207
+ azureBlob .delete (DeleteSnapshotsOption .NONE , null , null , client .v2 ().get ());
215
208
});
216
209
}
217
210
@@ -238,19 +231,17 @@ public Map<String, BlobMetaData> listBlobsByPrefix(String account, String contai
238
231
final CloudBlobContainer blobContainer = client .v1 ().getContainerReference (container );
239
232
logger .trace (() -> new ParameterizedMessage ("listing container [{}], keyPath [{}], prefix [{}]" , container , keyPath , prefix ));
240
233
SocketAccess .doPrivilegedVoidException (() -> {
241
- if (blobContainer .exists ()) {
242
- for (final ListBlobItem blobItem : blobContainer .listBlobs (keyPath + (prefix == null ? "" : prefix ), false ,
243
- enumBlobListingDetails , null , client .v2 ().get ())) {
244
- final URI uri = blobItem .getUri ();
245
- logger .trace (() -> new ParameterizedMessage ("blob url [{}]" , uri ));
246
- // uri.getPath is of the form /container/keyPath.* and we want to strip off the /container/
247
- // this requires 1 + container.length() + 1, with each 1 corresponding to one of the /
248
- final String blobPath = uri .getPath ().substring (1 + container .length () + 1 );
249
- final BlobProperties properties = ((CloudBlockBlob ) blobItem ).getProperties ();
250
- final String name = blobPath .substring (keyPath .length ());
251
- logger .trace (() -> new ParameterizedMessage ("blob url [{}], name [{}], size [{}]" , uri , name , properties .getLength ()));
252
- blobsBuilder .put (name , new PlainBlobMetaData (name , properties .getLength ()));
253
- }
234
+ for (final ListBlobItem blobItem : blobContainer .listBlobs (keyPath + (prefix == null ? "" : prefix ), false ,
235
+ enumBlobListingDetails , null , client .v2 ().get ())) {
236
+ final URI uri = blobItem .getUri ();
237
+ logger .trace (() -> new ParameterizedMessage ("blob url [{}]" , uri ));
238
+ // uri.getPath is of the form /container/keyPath.* and we want to strip off the /container/
239
+ // this requires 1 + container.length() + 1, with each 1 corresponding to one of the /
240
+ final String blobPath = uri .getPath ().substring (1 + container .length () + 1 );
241
+ final BlobProperties properties = ((CloudBlockBlob ) blobItem ).getProperties ();
242
+ final String name = blobPath .substring (keyPath .length ());
243
+ logger .trace (() -> new ParameterizedMessage ("blob url [{}], name [{}], size [{}]" , uri , name , properties .getLength ()));
244
+ blobsBuilder .put (name , new PlainBlobMetaData (name , properties .getLength ()));
254
245
}
255
246
});
256
247
return blobsBuilder .immutableMap ();
@@ -264,8 +255,8 @@ public void writeBlob(String account, String container, String blobName, InputSt
264
255
final CloudBlobContainer blobContainer = client .v1 ().getContainerReference (container );
265
256
final CloudBlockBlob blob = blobContainer .getBlockBlobReference (blobName );
266
257
try {
267
- SocketAccess .doPrivilegedVoidException (() -> blob . upload ( inputStream , blobSize , AccessCondition . generateIfNotExistsCondition (),
268
- null , client .v2 ().get ()));
258
+ SocketAccess .doPrivilegedVoidException (() ->
259
+ blob . upload ( inputStream , blobSize , AccessCondition . generateIfNotExistsCondition (), null , client .v2 ().get ()));
269
260
} catch (final StorageException se ) {
270
261
if (se .getHttpStatusCode () == HttpURLConnection .HTTP_CONFLICT &&
271
262
StorageErrorCodeStrings .BLOB_ALREADY_EXISTS .equals (se .getErrorCode ())) {
0 commit comments