Skip to content

Commit

Permalink
fix: relax catching and rethrowinbg IOExceptions to Throwable
Browse files Browse the repository at this point in the history
     bump to n5-3.1.3
  • Loading branch information
axtimwalde committed Feb 16, 2024
1 parent adfcfb2 commit 378229f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 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.1</n5.version>
<n5.version>3.1.3</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 @@ -505,7 +505,7 @@ protected JsonElement zarrToN5DatasetAttributes(final JsonElement elem ) {
attrs.add(DatasetAttributes.BLOCK_SIZE_KEY, attrs.get(ZArrayAttributes.chunksKey));
attrs.addProperty(DatasetAttributes.DATA_TYPE_KEY, zattrs.getDType().getDataType().toString());

JsonElement e = attrs.get(ZArrayAttributes.compressorKey);
final JsonElement e = attrs.get(ZArrayAttributes.compressorKey);
if (e == JsonNull.INSTANCE) {
attrs.add(DatasetAttributes.COMPRESSION_KEY, gson.toJsonTree(new RawCompression()));
} else {
Expand Down Expand Up @@ -636,7 +636,7 @@ public DataBlock<?> readBlock(

try (final LockedChannel lockedChannel = keyValueAccess.lockForReading(absolutePath)) {
return readBlock(lockedChannel.newInputStream(), zarrDatasetAttributes, gridPosition);
} catch (final IOException | UncheckedIOException e) {
} catch (final Throwable e) {
throw new N5IOException(
"Failed to read block " + Arrays.toString(gridPosition) + " from dataset " + pathName,
e);
Expand Down Expand Up @@ -685,9 +685,9 @@ protected static DataBlock<?> readBlock(
return dataBlock;
}

private static ZarrStringDataBlock readVLenStringBlock(InputStream in, BlockReader reader, ByteArrayDataBlock byteBlock) throws IOException {
private static ZarrStringDataBlock readVLenStringBlock(final InputStream in, final BlockReader reader, final ByteArrayDataBlock byteBlock) throws IOException {
// read whole chunk and deserialize; this should be improved
ZarrStringDataBlock dataBlock = new ZarrStringDataBlock(byteBlock.getSize(), byteBlock.getGridPosition(), new String[0]);
final ZarrStringDataBlock dataBlock = new ZarrStringDataBlock(byteBlock.getSize(), byteBlock.getGridPosition(), new String[0]);
if (reader instanceof BloscCompression) {
// Blosc reader reads actual data and doesn't care about buffer size (but needs special treatment in data block)
reader.read(dataBlock, in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import java.io.IOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
Expand All @@ -45,9 +44,9 @@
import org.janelia.saalfeldlab.n5.LockedChannel;
import org.janelia.saalfeldlab.n5.N5Exception;
import org.janelia.saalfeldlab.n5.N5Exception.N5IOException;
import org.janelia.saalfeldlab.n5.cache.N5JsonCache;
import org.janelia.saalfeldlab.n5.N5URI;
import org.janelia.saalfeldlab.n5.RawCompression;
import org.janelia.saalfeldlab.n5.cache.N5JsonCache;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down Expand Up @@ -137,6 +136,7 @@ public ZarrKeyValueWriter(
}
}

@Override
public void setVersion(final String path) throws N5Exception {

setVersion(path, false);
Expand Down Expand Up @@ -192,7 +192,7 @@ else if ( getCache().isDataset(normalPath, ZARRAY_FILE)){
// since the contents is null
try {
keyValueAccess.createDirectories(absoluteGroupPath(normalPath));
} catch (final IOException | UncheckedIOException e) {
} catch (final Throwable e) {
throw new N5Exception.N5IOException("Failed to create group " + path, e);
}

Expand Down Expand Up @@ -245,7 +245,7 @@ else if (getCache().isGroup(normalPath, ZGROUP_FILE)) {
final String absPath = absoluteGroupPath(normalPath);
try {
keyValueAccess.createDirectories(absPath);
} catch (final IOException | UncheckedIOException e) {
} catch (final Throwable e) {
throw new N5IOException("Failed to create directories " + absPath, e);
}

Expand Down Expand Up @@ -386,8 +386,8 @@ protected ZArrayAttributes createZArrayAttributes(final DatasetAttributes datase

/**
* Write the contents of the attributes argument to the .zarray file at
* the given pathName. Overwrites and existing .zarray.
*
* the given pathName. Overwrites and existing .zarray.
*
* @param pathName the group / dataset path
* @param attributes ZArray attributes
* @throws N5Exception the exception
Expand All @@ -407,7 +407,7 @@ protected void deleteJsonResource(final String normalPath, final String jsonName
final String absolutePath = keyValueAccess.compose(uri, normalPath, jsonName);
try {
keyValueAccess.delete(absolutePath);
} catch (IOException | UncheckedIOException e1) {
} catch (final Throwable e1) {
throw new N5IOException("Failed to delete " + absolutePath, e1);
}
}
Expand All @@ -423,7 +423,7 @@ protected void writeJsonResource(
final String absolutePath = keyValueAccess.compose(uri, normalPath, jsonName);
try (final LockedChannel lock = keyValueAccess.lockForWriting(absolutePath)) {
GsonUtils.writeAttributes(lock.newWriter(), attributes, gson);
} catch (final IOException | UncheckedIOException e) {
} catch (final Throwable e) {
throw new N5IOException("Failed to write " + absolutePath, e);
}
}
Expand Down Expand Up @@ -540,7 +540,7 @@ public <T> void writeBlock(
zarrDatasetAttributes,
dataBlock);
}
} catch (final IOException | UncheckedIOException e) {
} catch (final Throwable e) {
throw new N5IOException(
"Failed to write block " + Arrays.toString(dataBlock.getGridPosition()) + " into dataset " + path,
e);
Expand All @@ -567,7 +567,7 @@ public boolean deleteBlock(
try {
if (keyValueAccess.exists(absolutePath))
keyValueAccess.delete(absolutePath);
} catch (final IOException | UncheckedIOException e) {
} catch (final Throwable e) {
throw new N5IOException(
"Failed to delete block " + Arrays.toString(gridPosition) + " from dataset " + path,
e);
Expand Down Expand Up @@ -730,7 +730,7 @@ protected static ZarrJsonElements build(final JsonObject obj, final Gson gson )
* <p>
* Used when re-directing attributes to the appropriate zarr metadata files according to
* attribute keys.
*
*
* @param obj the json attributes object
* @param gson the json
* @param mapN5Attributes if true, map n5 attribute keys to corresponding zarr attribute keys
Expand Down Expand Up @@ -856,5 +856,4 @@ static void reorder(final JsonArray array) {
array.set(j, a);
}
}

}

0 comments on commit 378229f

Please sign in to comment.