|
1 | 1 | package dev.zarr.zarrjava.v2; |
2 | 2 |
|
| 3 | +import com.scalableminds.bloscjava.Blosc; |
3 | 4 | import dev.zarr.zarrjava.ZarrException; |
4 | 5 | import dev.zarr.zarrjava.core.chunkkeyencoding.Separator; |
5 | 6 | import dev.zarr.zarrjava.v2.codec.Codec; |
6 | | -import dev.zarr.zarrjava.v2.codec.CodecBuilder; |
7 | | - |
8 | | -import java.util.function.Function; |
| 7 | +import dev.zarr.zarrjava.v2.codec.core.BloscCodec; |
| 8 | +import dev.zarr.zarrjava.v2.codec.core.ZlibCodec; |
9 | 9 |
|
10 | 10 | public class ArrayMetadataBuilder { |
11 | 11 | long[] shape = null; |
@@ -64,38 +64,59 @@ public ArrayMetadataBuilder withFillValue(Object fillValue) { |
64 | 64 | return this; |
65 | 65 | } |
66 | 66 |
|
67 | | - public ArrayMetadataBuilder withFilters(Codec... filters) { |
68 | | - this.filters = filters; |
| 67 | + public ArrayMetadataBuilder withCompressor(Codec compressor) { |
| 68 | + this.compressor = compressor; |
69 | 69 | return this; |
70 | 70 | } |
71 | 71 |
|
72 | | - public ArrayMetadataBuilder withFilters(Function<CodecBuilder, CodecBuilder> codecBuilder) throws ZarrException { |
73 | | - if (dataType == null) { |
74 | | - throw new IllegalStateException("Please call `withDataType` first."); |
| 72 | + public ArrayMetadataBuilder withBloscCompressor( |
| 73 | + Blosc.Compressor cname, Blosc.Shuffle shuffle, int clevel, int typeSize, |
| 74 | + int blockSize |
| 75 | + ) { |
| 76 | + try { |
| 77 | + this.compressor = new BloscCodec(cname, shuffle, clevel, typeSize, blockSize); |
| 78 | + } catch (ZarrException e) { |
| 79 | + throw new RuntimeException(e); |
75 | 80 | } |
76 | | - CodecBuilder nestedCodecBuilder = new CodecBuilder(dataType); |
77 | | - this.filters = codecBuilder.apply(nestedCodecBuilder) |
78 | | - .build(); |
79 | 81 | return this; |
80 | 82 | } |
81 | 83 |
|
82 | | - public ArrayMetadataBuilder withCompressor(Codec compressor) { |
83 | | - this.compressor = compressor; |
84 | | - return this; |
| 84 | + public ArrayMetadataBuilder withBloscCompressor(String cname, String shuffle, int clevel, int blockSize) { |
| 85 | + if (shuffle.equals("shuffle")) { |
| 86 | + shuffle = "byteshuffle"; |
| 87 | + } |
| 88 | + return withBloscCompressor(Blosc.Compressor.fromString(cname), Blosc.Shuffle.fromString(shuffle), clevel, |
| 89 | + dataType.getByteCount(), blockSize |
| 90 | + ); |
85 | 91 | } |
86 | 92 |
|
87 | | - public ArrayMetadataBuilder withBloscCompressor(String cname, String shuffle, int clevel) { |
88 | | - this.compressor = new CodecBuilder(dataType) |
89 | | - .withBlosc(cname, shuffle, clevel) |
90 | | - .build()[0]; |
91 | | - return this; |
| 93 | + public ArrayMetadataBuilder withBloscCompressor(String cname, String shuffle, int clevel) { |
| 94 | + return withBloscCompressor(cname, shuffle, clevel, 0); |
| 95 | + } |
| 96 | + |
| 97 | + public ArrayMetadataBuilder withBloscCompressor(String cname, int clevel) { |
| 98 | + return withBloscCompressor(cname, "noshuffle", clevel); |
| 99 | + } |
| 100 | + |
| 101 | + public ArrayMetadataBuilder withBloscCompressor(String cname) { |
| 102 | + return withBloscCompressor(cname, 5); |
| 103 | + } |
| 104 | + |
| 105 | + public ArrayMetadataBuilder withBloscCompressor() { |
| 106 | + return withBloscCompressor("zstd"); |
92 | 107 | } |
93 | 108 |
|
94 | 109 | public ArrayMetadataBuilder withZlibCompressor(int level) { |
95 | | - this.compressor = new CodecBuilder(dataType) |
96 | | - .withZlib(level) |
97 | | - .build()[0]; |
98 | | - return this; |
| 110 | + try { |
| 111 | + this.compressor = new ZlibCodec(level); |
| 112 | + } catch (ZarrException e) { |
| 113 | + throw new RuntimeException(e); |
| 114 | + } |
| 115 | + return this; |
| 116 | + } |
| 117 | + |
| 118 | + public ArrayMetadataBuilder withZlibCompressor() { |
| 119 | + return withZlibCompressor(5); |
99 | 120 | } |
100 | 121 |
|
101 | 122 | public ArrayMetadata build() throws ZarrException { |
|
0 commit comments