Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ default DatasetAttributes getDatasetAttributes(final String pathName) {
return null;

if (cacheMeta()) {
attributes = getCache().getAttributes(normalPath, N5KeyValueReader.ATTRIBUTES_JSON);
attributes = getCache().getAttributes(normalPath, getAttributesKey());
} else {
attributes = GsonKeyValueN5Reader.super.getAttributes(normalPath);
}
Expand All @@ -99,7 +99,7 @@ default <T> T getAttribute(

final JsonElement attributes;
if (cacheMeta()) {
attributes = getCache().getAttributes(normalPathName, N5KeyValueReader.ATTRIBUTES_JSON);
attributes = getCache().getAttributes(normalPathName, getAttributesKey());
} else {
attributes = GsonKeyValueN5Reader.super.getAttributes(normalPathName);
}
Expand All @@ -120,7 +120,7 @@ default <T> T getAttribute(
final String normalizedAttributePath = N5URI.normalizeAttributePath(key);
JsonElement attributes;
if (cacheMeta()) {
attributes = getCache().getAttributes(normalPathName, N5KeyValueReader.ATTRIBUTES_JSON);
attributes = getCache().getAttributes(normalPathName, getAttributesKey());
} else {
attributes = GsonKeyValueN5Reader.super.getAttributes(normalPathName);
}
Expand All @@ -136,7 +136,7 @@ default boolean exists(final String pathName) {

final String normalPathName = N5URI.normalizeGroupPath(pathName);
if (cacheMeta())
return getCache().isGroup(normalPathName, N5KeyValueReader.ATTRIBUTES_JSON);
return getCache().isGroup(normalPathName, getAttributesKey());
else {
return existsFromContainer(normalPathName, null);
}
Expand Down Expand Up @@ -180,7 +180,7 @@ default boolean datasetExists(final String pathName) throws N5IOException {

final String normalPathName = N5URI.normalizeGroupPath(pathName);
if (cacheMeta()) {
return getCache().isDataset(normalPathName, N5KeyValueReader.ATTRIBUTES_JSON);
return getCache().isDataset(normalPathName, getAttributesKey());
}
return isDatasetFromContainer(normalPathName);
}
Expand Down Expand Up @@ -212,7 +212,7 @@ default JsonElement getAttributes(final String pathName) throws N5IOException {

/* If cached, return the cache */
if (cacheMeta()) {
return getCache().getAttributes(groupPath, N5KeyValueReader.ATTRIBUTES_JSON);
return getCache().getAttributes(groupPath, getAttributesKey());
} else {
return GsonKeyValueN5Reader.super.getAttributes(groupPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ default void createGroup(final String path) throws N5Exception {
// else if exists is true (then a dataset is present) so throw an exception to avoid
// overwriting / invalidating existing data
if (cacheMeta()) {
if (getCache().isGroup(normalPath, N5KeyValueReader.ATTRIBUTES_JSON))
if (getCache().isGroup(normalPath, getAttributesKey()))
return;
else if (getCache().exists(normalPath, N5KeyValueReader.ATTRIBUTES_JSON)) {
else if (getCache().exists(normalPath, getAttributesKey())) {
throw new N5Exception("Can't make a group on existing path.");
}
}
Expand All @@ -88,8 +88,8 @@ else if (getCache().exists(normalPath, N5KeyValueReader.ATTRIBUTES_JSON)) {
for (final String child : pathParts) {

final String childPath = parent.isEmpty() ? child : parent + "/" + child;
getCache().initializeNonemptyCache(childPath, N5KeyValueReader.ATTRIBUTES_JSON);
getCache().updateCacheInfo(childPath, N5KeyValueReader.ATTRIBUTES_JSON);
getCache().initializeNonemptyCache(childPath, getAttributesKey());
getCache().updateCacheInfo(childPath, getAttributesKey());

// only add if the parent exists and has children cached already
if (parent != null && !child.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public BlockCodecInfo getBlockCodecInfo() {
return blockCodecInfo;
}

public DataCodecInfo[] getDataCodecInfos() {

return dataCodecInfos;
}

@SuppressWarnings("unchecked")
<T> BlockCodec<T> getBlockCodec() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,6 @@ default String absoluteGroupPath(final String normalGroupPath) {
*/
default String absoluteAttributesPath(final String normalPath) {

return getKeyValueAccess().compose(getURI(), normalPath, N5KeyValueReader.ATTRIBUTES_JSON);
return getKeyValueAccess().compose(getURI(), normalPath, getAttributesKey());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ default <T> T removeAttribute(final String pathName, final String key, final Cla
throw new N5Exception.N5ClassCastException(e);
}
if (obj != null) {
writeAttributes(normalPath, attributes);
setAttributes(normalPath, attributes);
}
return obj;
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/janelia/saalfeldlab/n5/GsonN5Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public interface GsonN5Reader extends N5Reader {

Gson getGson();

/**
* Get the key for the {@link KeyValueAccess}, that is used for storing attributes.
*
* @return the attributes key
*/
String getAttributesKey();

@Override
default Map<String, Class<?>> listAttributes(final String pathName) throws N5Exception {

Expand Down
11 changes: 0 additions & 11 deletions src/main/java/org/janelia/saalfeldlab/n5/GsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@
import java.util.regex.Matcher;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import org.janelia.saalfeldlab.n5.N5Exception.N5JsonParseException;
import org.janelia.saalfeldlab.n5.codec.CodecInfo;

/**
* Utility class for working with JSON.
Expand All @@ -80,15 +78,6 @@
*/
public interface GsonUtils {

static Gson registerGson(final GsonBuilder gsonBuilder) {

gsonBuilder.registerTypeAdapter(DataType.class, new DataType.JsonAdapter());
gsonBuilder.registerTypeHierarchyAdapter(CodecInfo.class, NameConfigAdapter.getJsonAdapter(CodecInfo.class));
gsonBuilder.registerTypeHierarchyAdapter(Compression.class, CompressionAdapter.getJsonAdapter());
gsonBuilder.disableHtmlEscaping();
return gsonBuilder.create();
}

/**
* Reads the attributes json from a given {@link Reader}.
*
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/org/janelia/saalfeldlab/n5/N5KeyValueReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import com.google.gson.JsonElement;
import org.janelia.saalfeldlab.n5.cache.N5JsonCache;
import org.janelia.saalfeldlab.n5.codec.CodecInfo;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down Expand Up @@ -127,7 +128,7 @@ protected N5KeyValueReader(
throws N5Exception {

this.keyValueAccess = keyValueAccess;
this.gson = GsonUtils.registerGson(gsonBuilder);
this.gson = registerGson(gsonBuilder).create();
this.cacheMeta = cacheMeta;
this.cache = newCache();

Expand Down Expand Up @@ -159,12 +160,27 @@ private boolean inferExistence(String path) {
return attributes != null || exists(path);
}

protected GsonBuilder registerGson(final GsonBuilder gsonBuilder) {

gsonBuilder.registerTypeAdapter(DataType.class, new DataType.JsonAdapter());
gsonBuilder.registerTypeHierarchyAdapter(CodecInfo.class, NameConfigAdapter.getJsonAdapter(CodecInfo.class));
gsonBuilder.registerTypeHierarchyAdapter(Compression.class, CompressionAdapter.getJsonAdapter());
gsonBuilder.disableHtmlEscaping();
return gsonBuilder;
}

@Override
public Gson getGson() {

return gson;
}

@Override
public String getAttributesKey() {

return ATTRIBUTES_JSON;
}

@Override
public KeyValueAccess getKeyValueAccess() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class RawBlockCodecInfo implements BlockCodecInfo {

private static final long serialVersionUID = 3282569607795127005L;

public static final String TYPE = "rawbytes";
public static final String TYPE = "bytes";

@NameConfig.Parameter(value = "endian", optional = true)
private final ByteOrder byteOrder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,9 @@ public <W extends GsonKeyValueN5Writer, R extends GsonKeyValueN5Reader> HttpRead

writer.writeSerializedBlock(object, datasetPath, datasetAttributes, gridPosition);
}

@Override
public String getAttributesKey() {
return writer.getAttributesKey();
}
}