Skip to content

Commit

Permalink
perf skip isFile check during readBlock
Browse files Browse the repository at this point in the history
feat: add N5NoSuchKeyException
  • Loading branch information
cmhulbert committed Jul 10, 2024
1 parent 6b6d4d2 commit a14f5f8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ public FileSystemKeyValueAccess(final FileSystem fileSystem) {
@Override
public LockedFileChannel lockForReading(final String normalPath) throws IOException {

return new LockedFileChannel(normalPath, true);
try {
return new LockedFileChannel(normalPath, true);
} catch (NoSuchFileException e) {
throw new N5Exception.N5NoSuchKeyException("No such file", e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ default DataBlock<?> readBlock(
final long... gridPosition) throws N5Exception {

final String path = absoluteDataBlockPath(N5URI.normalizeGroupPath(pathName), gridPosition);
if (!getKeyValueAccess().isFile(path))
return null;

try (final LockedChannel lockedChannel = getKeyValueAccess().lockForReading(path)) {
return DefaultBlockReader.readBlock(lockedChannel.newInputStream(), datasetAttributes, gridPosition);
} catch (final N5Exception.N5NoSuchKeyException e) {
return null;
} catch (final IOException | UncheckedIOException e) {
throw new N5IOException(
"Failed to read block " + Arrays.toString(gridPosition) + " from dataset " + path,
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/org/janelia/saalfeldlab/n5/N5Exception.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,31 @@ protected N5ClassCastException(
super(message, cause, enableSuppression, writableStackTrace);
}
}

public static class N5NoSuchKeyException extends N5IOException {

public N5NoSuchKeyException(final String message) {

super(message);
}

public N5NoSuchKeyException(final String message, final Throwable cause) {

super(message, cause);
}

public N5NoSuchKeyException(final Throwable cause) {

super(cause);
}

protected N5NoSuchKeyException(
final String message,
final Throwable cause,
final boolean enableSuppression,
final boolean writableStackTrace) {

super(message, cause, enableSuppression, writableStackTrace);
}
}
}

0 comments on commit a14f5f8

Please sign in to comment.