Skip to content

Commit 574b1c0

Browse files
committed
adopt feedback
1 parent 33af688 commit 574b1c0

3 files changed

Lines changed: 48 additions & 103 deletions

File tree

src/main/java/dev/zarr/zarrjava/core/Array.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
public interface Array {
1818

1919
ArrayMetadata metadata();
20+
21+
StoreHandle storeHandle();
22+
23+
CodecPipeline codecPipeline();
2024

2125
/**
2226
* Writes a ucar.ma2.Array into the Zarr array at a specified offset. The shape of the Zarr array
@@ -203,11 +207,6 @@ default boolean chunkIsInArray(long[] chunkCoords) {
203207
return true;
204208
}
205209

206-
207-
StoreHandle storeHandle();
208-
209-
CodecPipeline codecPipeline();
210-
211210
/**
212211
* Reads a part of the Zarr array based on a requested offset and shape into an ucar.ma2.Array.
213212
*

src/main/java/dev/zarr/zarrjava/v2/ArrayMetadataBuilder.java

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package dev.zarr.zarrjava.v2;
22

3+
import com.scalableminds.bloscjava.Blosc;
34
import dev.zarr.zarrjava.ZarrException;
45
import dev.zarr.zarrjava.core.chunkkeyencoding.Separator;
56
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;
99

1010
public class ArrayMetadataBuilder {
1111
long[] shape = null;
@@ -64,38 +64,59 @@ public ArrayMetadataBuilder withFillValue(Object fillValue) {
6464
return this;
6565
}
6666

67-
public ArrayMetadataBuilder withFilters(Codec... filters) {
68-
this.filters = filters;
67+
public ArrayMetadataBuilder withCompressor(Codec compressor) {
68+
this.compressor = compressor;
6969
return this;
7070
}
7171

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);
7580
}
76-
CodecBuilder nestedCodecBuilder = new CodecBuilder(dataType);
77-
this.filters = codecBuilder.apply(nestedCodecBuilder)
78-
.build();
7981
return this;
8082
}
8183

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+
);
8591
}
8692

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");
92107
}
93108

94109
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);
99120
}
100121

101122
public ArrayMetadata build() throws ZarrException {

src/main/java/dev/zarr/zarrjava/v2/codec/CodecBuilder.java

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)