Skip to content

Commit 84dea5b

Browse files
committed
fix: handling of null blocks by DefaultDatasetAccess
* necessary for saveNonEmptyBlocks in n5-imglib2
1 parent 730d9f6 commit 84dea5b

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/main/java/org/janelia/saalfeldlab/n5/shard/DefaultDatasetAccess.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ private ReadData writeRegionRecursive(
360360
: codec.decode(existingReadData, gridPosition);
361361
final DataBlock<T> dataBlock = blocks.get(gridPosition, existingDataBlock);
362362

363+
// null blocks may be provided when they contain only the fill value
364+
// and only non-empty blocks should be written, for example
365+
if (dataBlock == null)
366+
return null;
367+
363368
return codec.encode(dataBlock);
364369
} else {
365370

src/main/java/org/janelia/saalfeldlab/n5/shard/PositionValueAccess.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ public ReadData get(long[] key) throws N5IOException {
108108
@Override
109109
public void put(long[] key, ReadData data) throws N5IOException {
110110

111+
// TODO is this the behavior we want?
112+
// if so, consider changing this method's name to 'update', say
113+
if (data == null) {
114+
remove(key);
115+
return;
116+
}
117+
111118
try ( final LockedChannel ch = kva.lockForWriting(absolutePath(key));
112119
final OutputStream outputStream = ch.newOutputStream();) {
113120
data.writeTo(outputStream);

0 commit comments

Comments
 (0)