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