Skip to content

Commit

Permalink
Merge pull request #37 from cmhulbert/fix/compressor
Browse files Browse the repository at this point in the history
Fix/compressor
  • Loading branch information
bogovicj authored Mar 4, 2024
2 parents 6c9182c + 43f9c44 commit 0afb158
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 164 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@

<json-simple.version>1.1.1</json-simple.version>

<n5.version>3.1.3</n5.version>
<n5.version>3.2.0</n5.version>
<n5-zstandard.version>1.0.2</n5-zstandard.version>

</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.google.gson.JsonNull;
import com.google.gson.JsonSerializer;
import org.janelia.saalfeldlab.n5.Bzip2Compression;
import org.janelia.saalfeldlab.n5.Compression;
import org.janelia.saalfeldlab.n5.GzipCompression;
Expand Down Expand Up @@ -265,12 +267,12 @@ public Bzip2Compression getCompression() {
}
}

public static class Raw extends RawCompression implements ZarrCompressor {

class Raw implements ZarrCompressor {
public Raw() {}
@Override
public RawCompression getCompression() {

return this;
return new RawCompression();
}
}

Expand All @@ -294,4 +296,6 @@ public ZarrCompressor deserialize(final JsonElement json, final Type typeOfT, fi
return context.deserialize(json, compressorClass);
}
}

JsonSerializer<Raw> rawNullAdapter = (src, typeOfSrc, context) -> JsonNull.INSTANCE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ public ZarrKeyValueReader(
final boolean cacheMeta)
throws N5Exception {

this(checkVersion, keyValueAccess, basePath, gsonBuilder, mapN5DatasetAttributes, mergeAttributes, cacheMeta, true);
}

protected ZarrKeyValueReader(
final boolean checkVersion,
final KeyValueAccess keyValueAccess,
final String basePath,
final GsonBuilder gsonBuilder,
final boolean mapN5DatasetAttributes,
final boolean mergeAttributes,
final boolean cacheMeta,
final boolean checkRootExists
) {


this.keyValueAccess = keyValueAccess;
this.gson = registerGson(gsonBuilder);
this.cacheMeta = cacheMeta;
Expand All @@ -169,6 +184,10 @@ public ZarrKeyValueReader(
cache = newCache();
else
cache = null;

if( checkRootExists && !exists("/"))
throw new N5Exception.N5IOException("No container exists at " + basePath );

}

/**
Expand Down Expand Up @@ -837,6 +856,7 @@ protected static GsonBuilder addTypeAdapters(final GsonBuilder gsonBuilder) {

gsonBuilder.registerTypeAdapter(DataType.class, new DataType.JsonAdapter());
gsonBuilder.registerTypeAdapter(ZarrCompressor.class, ZarrCompressor.jsonAdapter);
gsonBuilder.registerTypeAdapter(ZarrCompressor.Raw.class, ZarrCompressor.rawNullAdapter);
gsonBuilder.registerTypeHierarchyAdapter(Compression.class, CompressionAdapter.getJsonAdapter());
gsonBuilder.registerTypeAdapter(Compression.class, CompressionAdapter.getJsonAdapter());
gsonBuilder.registerTypeAdapter(ZArrayAttributes.class, ZArrayAttributes.jsonAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public ZarrKeyValueWriter(
gsonBuilder,
mapN5DatasetAttributes,
mergeAttributes,
cacheAttributes);
cacheAttributes,
false);
this.dimensionSeparator = dimensionSeparator;
Version version = null;
if (exists("/")) {
Expand Down
Loading

0 comments on commit 0afb158

Please sign in to comment.