Skip to content

Commit

Permalink
Merge pull request #37 from saalfeldlab/perf/skipIsFile
Browse files Browse the repository at this point in the history
perf: throw N5NoSuchKeyException if no key when reading
  • Loading branch information
bogovicj authored Jul 16, 2024
2 parents 2948214 + ba5020b commit 6dac14d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>37.0.0</version>
<version>38.0.1</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -120,7 +120,7 @@

<s3mock_2.12.version>0.2.5</s3mock_2.12.version>
<jaxb-api.version>2.2.2</jaxb-api.version>
<n5.version>3.2.0</n5.version>
<n5.version>3.3.0</n5.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
import java.util.List;
import java.util.stream.Collectors;

import com.amazonaws.services.s3.AmazonS3URI;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.s3.model.S3Object;
import org.janelia.saalfeldlab.n5.KeyValueAccess;
import org.janelia.saalfeldlab.n5.LockedChannel;
import org.janelia.saalfeldlab.n5.N5Exception;
Expand Down Expand Up @@ -602,7 +603,15 @@ private void checkWritable() {
@Override
public InputStream newInputStream() {

final S3ObjectInputStream in = s3.getObject(bucketName, path).getObjectContent();
final S3Object object;
try {
object = s3.getObject(bucketName, path);
} catch (final AmazonServiceException e) {
if (e.getStatusCode() == 404)
throw new N5Exception.N5NoSuchKeyException("No such key", e);
throw e;
}
final S3ObjectInputStream in = object.getObjectContent();
final S3ObjectInputStreamDrain s3in = new S3ObjectInputStreamDrain(in);
synchronized (resources) {
resources.add(s3in);
Expand Down

0 comments on commit 6dac14d

Please sign in to comment.