@@ -328,27 +328,14 @@ public String getDirectory(String directoryName) {
328328 }
329329 }
330330
331- public boolean existsDirectory (String directoryName ) {
332- directoryName = StorageUtils .normalizeDirectoryName (directoryName );
333- ListObjectsRequest listObjectsRequest = new ListObjectsRequest ()
334- .withBucketName (bucket ).withDelimiter (StorageUtils .DELIMITER );
335- List <String > directories = new ArrayList <String >();
336- for (String prefix : client .listObjects (listObjectsRequest ).getCommonPrefixes ()) {
337- directories .add (prefix );
338- getAllDirectories (prefix , directories );
339- }
340- return directories .contains (directoryName );
341- }
342-
343- public void getAllDirectories (String directoryName , List <String > directories ) {
344- directoryName = StorageUtils .normalizeDirectoryName (directoryName );
345- ListObjectsRequest listObjectsRequest = new ListObjectsRequest ()
346- .withBucketName (bucket ).withPrefix (directoryName ).withDelimiter (StorageUtils .DELIMITER );
347- for (String prefix : client .listObjects (listObjectsRequest ).getCommonPrefixes ()) {
348- directories .add (prefix );
349- getAllDirectories (prefix , directories );
350- }
351- }
331+ public boolean existsDirectory (String directoryName ) {
332+ ListObjectsV2Request listObjectsRequest = new ListObjectsV2Request ()
333+ .withBucketName (bucket )
334+ .withDelimiter (StorageUtils .DELIMITER )
335+ .withPrefix (StorageUtils .normalizeDirectoryName (directoryName ))
336+ .withMaxKeys (1 );
337+ return client .listObjectsV2 (listObjectsRequest ).getKeyCount () > 0 ;
338+ }
352339
353340 public void createDirectory (String directoryName ) {
354341 ensureFolder (directoryName );
0 commit comments