|
2 | 2 |
|
3 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; |
4 | 4 | import dev.zarr.zarrjava.ZarrException; |
| 5 | +import dev.zarr.zarrjava.store.FilesystemStore; |
5 | 6 | import dev.zarr.zarrjava.store.StoreHandle; |
6 | 7 | import dev.zarr.zarrjava.utils.Utils; |
7 | 8 | import dev.zarr.zarrjava.core.codec.CodecPipeline; |
8 | 9 | import java.io.IOException; |
9 | 10 | import java.nio.ByteBuffer; |
| 11 | +import java.nio.file.Path; |
| 12 | +import java.nio.file.Paths; |
10 | 13 | import java.util.Arrays; |
11 | 14 | import java.util.HashMap; |
12 | 15 | import java.util.Map; |
@@ -47,6 +50,58 @@ public static Array open(StoreHandle storeHandle) throws IOException, ZarrExcept |
47 | 50 | ); |
48 | 51 | } |
49 | 52 |
|
| 53 | + /** |
| 54 | + * Opens an existing Zarr array at a specified storage location using a Path. |
| 55 | + * |
| 56 | + * @param path the storage location of the Zarr array |
| 57 | + * @throws IOException if the metadata cannot be read |
| 58 | + * @throws ZarrException if the Zarr array cannot be opened |
| 59 | + */ |
| 60 | + public static Array open(Path path) throws IOException, ZarrException { |
| 61 | + return open(new FilesystemStore(path).resolve()); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Opens an existing Zarr array at a specified storage location using a String path. |
| 66 | + * |
| 67 | + * @param path the storage location of the Zarr array |
| 68 | + * @throws IOException if the metadata cannot be read |
| 69 | + * @throws ZarrException if the Zarr array cannot be opened |
| 70 | + */ |
| 71 | + public static Array open(String path) throws IOException, ZarrException { |
| 72 | + return open(Paths.get(path)); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Creates a new Zarr array with the provided metadata at a specified storage location. This |
| 77 | + * method will raise an exception if a Zarr array already exists at the specified storage |
| 78 | + * location. |
| 79 | + * |
| 80 | + * @param path the storage location of the Zarr array |
| 81 | + * @param arrayMetadata the metadata of the Zarr array |
| 82 | + * @throws IOException if the metadata cannot be serialized |
| 83 | + * @throws ZarrException if the Zarr array cannot be created |
| 84 | + */ |
| 85 | + public static Array create(Path path, ArrayMetadata arrayMetadata) |
| 86 | + throws IOException, ZarrException { |
| 87 | + return Array.create(new FilesystemStore(path).resolve(), arrayMetadata); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Creates a new Zarr array with the provided metadata at a specified storage location. This |
| 92 | + * method will raise an exception if a Zarr array already exists at the specified storage |
| 93 | + * location. |
| 94 | + * |
| 95 | + * @param path the storage location of the Zarr array |
| 96 | + * @param arrayMetadata the metadata of the Zarr array |
| 97 | + * @throws IOException if the metadata cannot be serialized |
| 98 | + * @throws ZarrException if the Zarr array cannot be created |
| 99 | + */ |
| 100 | + public static Array create(String path, ArrayMetadata arrayMetadata) |
| 101 | + throws IOException, ZarrException { |
| 102 | + return Array.create(Paths.get(path), arrayMetadata); |
| 103 | + } |
| 104 | + |
50 | 105 | /** |
51 | 106 | * Creates a new Zarr array with the provided metadata at a specified storage location. This |
52 | 107 | * method will raise an exception if a Zarr array already exists at the specified storage |
@@ -106,6 +161,16 @@ public static Array create(StoreHandle storeHandle, |
106 | 161 | arrayMetadataBuilderMapper.apply(new ArrayMetadataBuilder()).build(), existsOk); |
107 | 162 | } |
108 | 163 |
|
| 164 | + public static Array create(Path path, Function<ArrayMetadataBuilder, ArrayMetadataBuilder> arrayMetadataBuilderMapper, boolean existsOk) |
| 165 | + throws IOException, ZarrException { |
| 166 | + return Array.create(new FilesystemStore(path).resolve(), arrayMetadataBuilderMapper, existsOk); |
| 167 | + } |
| 168 | + |
| 169 | + public static Array create(String path, Function<ArrayMetadataBuilder, ArrayMetadataBuilder> arrayMetadataBuilderMapper, boolean existsOk) |
| 170 | + throws IOException, ZarrException { |
| 171 | + return Array.create(Paths.get(path), arrayMetadataBuilderMapper, existsOk); |
| 172 | + } |
| 173 | + |
109 | 174 | @Nonnull |
110 | 175 | public static ArrayMetadataBuilder metadataBuilder() { |
111 | 176 | return new ArrayMetadataBuilder(); |
|
0 commit comments