File tree Expand file tree Collapse file tree
src/main/java/dev/zarr/zarrjava/store Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212import java .io .IOException ;
1313import java .io .InputStream ;
1414import java .nio .ByteBuffer ;
15+ import java .util .ArrayList ;
16+ import java .util .List ;
1517import java .util .stream .Stream ;
1618
1719public class S3Store implements Store , Store .ListableStore {
@@ -110,9 +112,20 @@ public Stream<String[]> list(String[] keys) {
110112 .bucket (bucketName ).prefix (fullKey )
111113 .build ();
112114 ListObjectsResponse res = s3client .listObjects (req );
113- return res .contents ()
114- .stream ()
115- .map (p -> p .key ().substring (fullKey .length () + 1 ).split ("/" ));
115+ return res .contents ().stream ()
116+ .map (S3Object ::key )
117+ .flatMap (key -> {
118+ List <String > pathSegments = new ArrayList <>();
119+ int index = fullKey .length ();
120+ while ((index = key .indexOf ('/' , index + 1 )) != -1 ) {
121+ pathSegments .add (key .substring (fullKey .length () + 1 , index ));
122+ }
123+ pathSegments .add (key .substring (fullKey .length () + 1 ));
124+ return pathSegments .stream ();
125+ })
126+ .distinct ()
127+ .map (s -> s .split ("/" ))
128+ .filter (arr -> arr .length > 0 );
116129 }
117130
118131 @ Nonnull
You can’t perform that action at this time.
0 commit comments