@@ -24,10 +24,17 @@ protected Group(@Nonnull StoreHandle storeHandle, @Nonnull GroupMetadata groupMe
2424 }
2525
2626 public static Group open (@ Nonnull StoreHandle storeHandle ) throws IOException {
27- StoreHandle metadataHandle = storeHandle .resolve (ZGROUP );
28- ByteBuffer metadataBytes = metadataHandle .readNonNull ();
29- return new Group (storeHandle , makeObjectMapper ()
30- .readValue (Utils .toArray (metadataBytes ), GroupMetadata .class ));
27+ ObjectMapper mapper = makeObjectMapper ();
28+ GroupMetadata metadata = mapper .readValue (
29+ Utils .toArray (storeHandle .resolve (ZGROUP ).readNonNull ()),
30+ GroupMetadata .class
31+ );
32+ if (storeHandle .resolve (ZATTRS ).exists ())
33+ metadata .attributes = mapper .readValue (
34+ Utils .toArray (storeHandle .resolve (ZATTRS ).readNonNull ()),
35+ dev .zarr .zarrjava .core .Attributes .class
36+ );
37+ return new Group (storeHandle , metadata );
3138 }
3239
3340 public static Group open (Path path ) throws IOException {
@@ -44,6 +51,12 @@ public static Group create(
4451 ObjectMapper objectMapper = makeObjectMapper ();
4552 ByteBuffer metadataBytes = ByteBuffer .wrap (objectMapper .writeValueAsBytes (groupMetadata ));
4653 storeHandle .resolve (ZGROUP ).set (metadataBytes );
54+ if (groupMetadata .attributes != null ) {
55+ StoreHandle attrsHandle = storeHandle .resolve (ZATTRS );
56+ ByteBuffer attrsBytes = ByteBuffer .wrap (
57+ objectMapper .writeValueAsBytes (groupMetadata .attributes ));
58+ attrsHandle .set (attrsBytes );
59+ }
4760 return new Group (storeHandle , groupMetadata );
4861 }
4962
@@ -87,4 +100,9 @@ public Array createArray(String key, Function<ArrayMetadataBuilder, ArrayMetadat
87100 public String toString () {
88101 return String .format ("<v2.Group {%s}>" , storeHandle );
89102 }
103+
104+ @ Override
105+ public dev .zarr .zarrjava .core .GroupMetadata metadata () {
106+ return metadata ;
107+ }
90108}
0 commit comments